all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Lukas Wagner" <l.wagner@proxmox.com>
To: "Thomas Ellmenreich" <t.ellmenreich@proxmox.com>,
	<pdm-devel@lists.proxmox.com>
Subject: Re: [PATCH proxmox v2 2/4] fix #6081: log: replace simple level filter with env filter
Date: Fri, 02 Oct 2026 10:10:12 +0200	[thread overview]
Message-ID: <DLU77IM9T97D.2BA9R0R31M4RT@proxmox.com> (raw)
In-Reply-To: <20260923115815.211083-3-t.ellmenreich@proxmox.com>

On Wed Sep 23, 2026 at 1:58 PM CEST, Thomas Ellmenreich wrote:
> Instead of parsing the contents of the environment variable passed to the
> Logger as a simple LevelFilter, parse them as an EnvFilter [0]. This is
> backwards compatible, as a simple LevelFilter [1] string is parsable as
> an EnvFilter.
>

Looks good to me, one small note inline.

> +
> +    /// If present, tries to parse the `env_filter_str` as a [`EnvFilter`],
> +    /// otherwiese falls back to the provided default log level.
> +    ///
> +    /// The provided default log level is a application default defined by us.
> +    /// The user can define their own default as part of the [`EnvFilter`]
> +    ///
> +    /// * `env_filter_str` - The log settings that would usually be written into
> +    ///                      a environment variable and then extracted by [`get_env_variable`]
> +    /// * `default_log_level` - Default log level used by the [`Logger`] in
> +    ///                         case the log settings are empty.

Thanks for the extensive documentation!

This produceds 2 clippy warnings (warning: doc list item overindented),
please fix these for the next iteration of this series.

> +    fn apply_default_log_level(
> +        env_filter_str: Option<String>,
> +        default_log_level: LevelFilter,
> +    ) -> EnvFilter {
> +        if let Some(env_filter_str) = env_filter_str {
> +            match EnvFilter::try_new(env_filter_str) {
> +                Ok(filter) => return filter,
> +                Err(e) => eprintln!("unable to parse the log env variable: {e:#}"),
> +            }
> +        }
> +        EnvFilter::default().add_directive(default_log_level.into())
> +    }
>  }
> +
> diff --git a/proxmox-log/src/lib.rs b/proxmox-log/src/lib.rs
> index 2d321f20..32c10e27 100644
> --- a/proxmox-log/src/lib.rs
> +++ b/proxmox-log/src/lib.rs
> @@ -1,7 +1,6 @@
>  #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
>  #![deny(unsafe_op_in_unsafe_fn)]
>  
> -use std::env;
>  use std::future::Future;
>  use std::sync::{Arc, Mutex};
>  
> @@ -147,21 +146,6 @@ where
>          .with_writer(std::io::stderr)
>  }
>  
> -fn get_env_variable(env_var: &str, default_log_level: LevelFilter) -> LevelFilter {
> -    let mut log_level = default_log_level;
> -    if let Ok(v) = env::var(env_var) {
> -        match v.parse::<LevelFilter>() {
> -            Ok(l) => {
> -                log_level = l;
> -            }
> -            Err(e) => {
> -                eprintln!("env variable {env_var} found, but parsing failed: {e:?}");
> -            }
> -        }
> -    }
> -    log_level
> -}
> -
>  /// Initialize tracing logger that prints to journald or stderr depending on if we are in a pbs
>  /// task.
>  ///





  reply	other threads:[~2026-10-02  8:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 11:57 [RFC datacenter-manager/proxmox v2 0/4] log: allow finegrained control logging levels Thomas Ellmenreich
2026-09-23 11:57 ` [PATCH proxmox v2 1/4] log: replace per layer filtering by one global filter Thomas Ellmenreich
2026-10-02  8:10   ` Lukas Wagner
2026-09-23 11:58 ` [PATCH proxmox v2 2/4] fix #6081: log: replace simple level filter with env filter Thomas Ellmenreich
2026-10-02  8:10   ` Lukas Wagner [this message]
2026-09-23 11:58 ` [PATCH proxmox v2 3/4] log: add tests to the logger Thomas Ellmenreich
2026-10-02  8:10   ` Lukas Wagner
2026-09-23 11:58 ` [PATCH datacenter-manager v2 4/4] api: set REST server debug level based on actual log level Thomas Ellmenreich
2026-10-02  8:10 ` [RFC datacenter-manager/proxmox v2 0/4] log: allow finegrained control logging levels Lukas Wagner
2026-10-02  9:34   ` Thomas Ellmenreich
2026-10-02  9:44     ` Lukas Wagner
2026-10-02 10:00       ` Thomas Ellmenreich
2026-10-02 10:59         ` Lukas Wagner

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=DLU77IM9T97D.2BA9R0R31M4RT@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    --cc=t.ellmenreich@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal