From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id E2D701FF173
	for <inbox@lore.proxmox.com>; Mon, 10 Feb 2025 17:43:11 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 70E6413DD4;
	Mon, 10 Feb 2025 17:43:09 +0100 (CET)
Date: Mon, 10 Feb 2025 17:42:35 +0100
From: Gabriel Goller <g.goller@proxmox.com>
To: Wolfgang Bumiller <w.bumiller@proxmox.com>
Message-ID: <yyzfsgf2p5k52fk67lsu6jzu42egxjqnfgywuermm75ijm7cwg@v4x56bymmlxq>
References: <20241209104606.263045-1-g.goller@proxmox.com>
 <20241209104606.263045-2-g.goller@proxmox.com>
 <5cettqvqg6i6y2cgihynjjirl4vyl6c5l3ewbn4ydhccpgc6ac@aj5yojr624d4>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <5cettqvqg6i6y2cgihynjjirl4vyl6c5l3ewbn4ydhccpgc6ac@aj5yojr624d4>
User-Agent: NeoMutt/20241002-35-39f9a6
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.032 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pbs-devel] [PATCH proxmox v2 1/4] log: rename/move init
 functions
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Cc: Lukas Wagner <l.wagner@proxmox.com>, pbs-devel@lists.proxmox.com
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

On 10.02.2025 15:37, Wolfgang Bumiller wrote:
>On Mon, Dec 09, 2024 at 11:46:03AM +0100, Gabriel Goller wrote:
>> +/// Inits a new tracing logger that prints to stderr or tasklog with the logging level specified in the
>> +/// environment variable `env_var`.
>> +///
>> +/// This logger is task-aware, which means if we are in a PBS task, we will retrieve the task-file
>> +/// and write to it. We'll only write to stderr if we are not in a task. If `env_var` doesn't exist
>> +/// or can't be read, use the `default_log_level`. The output will be very plain: no ansi, no
>> +/// timestamp, no level, just the message and it's
>> +/// fields.
>> +pub fn stderr_or_tasklog(
>> +    env_var: &str,
>> +    default_log_level: LevelFilter,
>> +) -> Result<(), anyhow::Error> {
>> +    let log_level = get_env_variable(env_var, default_log_level);
>> +
>> +    let registry = tracing_subscriber::registry()
>> +        .with(
>> +            plain_stderr_layer()
>> +                .with_filter(filter_fn(|_metadata| !LogContext::exists()))
>
>^ This condition misses the `Level::ERROR` comparison while being
>suggested as a replacement for `init_cli_logger` which had it (not
>visible in the patch context lines, but it's there).
>If this is done on purpose, please explain it in the commit message.

Oops, yeah my bad, this should be 

     !LogContext::exists() || *metadata.level() == Level::ERROR

What do you think about the rest of the patch? I tried to implement this
with a builder pattern as well, but it turned out to be quite tricky
moving the layers around so I just wrote a ton of functions with long
names :(

>If this was an oversight, the functions in `lib.rs` could just call
>their recommended `init::` counterparts instead of reimplementing them.

Yep, will do that as well!

>> +                .with_filter(log_level),
>> +        )
>> +        .with(TasklogLayer {}.with_filter(log_level));
>> +
>> +    tracing::subscriber::set_global_default(registry)?;
>> +    LogTracer::init_with_filter(log_level.as_log())?;
>> +    Ok(())
>> +}

Thanks for the review!


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel