public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [RFC proxmox 2/2] proxmox-log: added tracing infra
Date: Fri, 13 Oct 2023 14:36:22 +0200	[thread overview]
Message-ID: <aab6ffa6-4ac4-45d2-a533-66109ebf73ec@proxmox.com> (raw)
In-Reply-To: <20231011140102.273423-3-g.goller@proxmox.com>

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Some things that are gonna get fixed with v2:

On 10/11/23 16:01, Gabriel Goller wrote:
> [..]
> +
> +tokio::task_local! {
> +    pub static LOGGER: RefCell<Option<FileLogger>>;
> +    pub static WARN_COUNTER: RefCell<Option<u64>>;
> +}
Move the `task_local!` stuff to the lib.rs file, that is
probably cleaner...
> [..]
> +
> +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));
> +
We also need the `.with_filter(log_level)` on the `FilelogLayer`, so
that the PBS_LOG variable also sets the log level on the task logs.
> +    tracing::subscriber::set_global_default(registry)?;
> +
> +    LogTracer::init()?;

Use `init_with_filter` here, so that we also set the loglevel on the 
(underlying) `log`
implementation. Like that a `log::info` call for example doesn't even
forward the message to `tracing`.

> +    Ok(())
> +}
> [..]

[-- Attachment #2: Type: text/html, Size: 2368 bytes --]

  reply	other threads:[~2023-10-13 12:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11 14:01 [pbs-devel] [RFC proxmox-backup 0/2] Tasklog rewrite with tracing Gabriel Goller
2023-10-11 14:01 ` [pbs-devel] [RFC proxmox-backup 1/2] log: removed task_log! macro and moved to tracing Gabriel Goller
2023-10-11 14:01 ` [pbs-devel] [RFC proxmox 2/2] proxmox-log: added tracing infra Gabriel Goller
2023-10-13 12:36   ` Gabriel Goller [this message]
2023-10-18 13:26   ` Dominik Csapak
2023-10-23  8:56     ` Gabriel Goller
2023-10-23  9:11       ` Gabriel Goller
2023-10-18 13:12 ` [pbs-devel] [RFC proxmox-backup 0/2] Tasklog rewrite with tracing Dominik Csapak
2023-10-23  9:09   ` Gabriel Goller
2023-10-23  9:29     ` Dominik Csapak
2023-10-23 11:43       ` Gabriel Goller
2023-10-23 14:33       ` Thomas Lamprecht
2023-10-24 13:44         ` Gabriel Goller
2023-10-25 13:55           ` Gabriel Goller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aab6ffa6-4ac4-45d2-a533-66109ebf73ec@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal