<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Some things that are gonna get fixed with v2:<br>
    </p>
    <div class="moz-cite-prefix">On 10/11/23 16:01, Gabriel Goller
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20231011140102.273423-3-g.goller@proxmox.com">
      <pre class="moz-quote-pre" wrap="">[..]
+
+tokio::task_local! {
+    pub static LOGGER: RefCell<Option<FileLogger>>;
+    pub static WARN_COUNTER: RefCell<Option<u64>>;
+}</pre>
    </blockquote>
    Move the `task_local!` stuff to the lib.rs file, that is<br>
    probably cleaner...<span style="white-space: pre-wrap">
</span>
    <blockquote type="cite"
      cite="mid:20231011140102.273423-3-g.goller@proxmox.com">
      <pre class="moz-quote-pre" wrap="">[..]
+
+pub fn init_logger(
+    env_var_name: &str,
+    default_log_level: LevelFilter,
+    application_name: &str,
+) -> Result<(), anyhow::Error> {
+    let mut log_level = default_log_level;
+    if let Ok(v) = env::var(env_var_name) {
+        if let Ok(l) = v.parse::<LevelFilter>() {
+            log_level = l;
+        }
+    }
+    let registry = tracing_subscriber::registry()
+        .with(FilelogLayer::new().with_filter(filter_fn(|metadata| {
+            metadata.fields().field("tasklog").is_some()
+        })))
+        .with(SyslogLayer::new(application_name.to_string()).with_filter(log_level));
+</pre>
    </blockquote>
    We also need the `.with_filter(log_level)` on the `FilelogLayer`, so<br>
    that the PBS_LOG variable also sets the log level on the task logs.<br>
    <blockquote type="cite"
      cite="mid:20231011140102.273423-3-g.goller@proxmox.com">
      <pre class="moz-quote-pre" wrap="">
+    tracing::subscriber::set_global_default(registry)?;
+
+    LogTracer::init()?;</pre>
    </blockquote>
    <p>Use `init_with_filter` here, so that we also set the loglevel on
      the (underlying) `log`<br>
      implementation. Like that a `log::info` call for example doesn't
      even<br>
      forward the message to `tracing`.<br>
    </p>
    <blockquote type="cite"
      cite="mid:20231011140102.273423-3-g.goller@proxmox.com">
      <pre class="moz-quote-pre" wrap="">
+    Ok(())
+}
[..]
</pre>
    </blockquote>
  </body>
</html>