MoSal

joined 1 year ago
[–] MoSal@lemmyrs.org 5 points 1 year ago

It's weird how much difference a year makes in the Rust world. I had some initial pushback in this PR from 11 months ago, which only expanded the scope of recommendation for tracking Cargo.lock a little.

[–] MoSal@lemmyrs.org 7 points 1 year ago (1 children)

This is not how the resolver works. A comment from the GitHub thread explains it well:

Cargo.lock is not active when you simply use some software, for libraries used as a dependency it's completely ignored, for applications installed via cargo install it's ignored by default but can be enabled with cargo install --locked. Only when you are building from within the source tree is it active (e.g. via cloning the repo, or manually downloading and extracting the archive).

[–] MoSal@lemmyrs.org 1 points 1 year ago

I think tracing-appender is not directly relevant here.

Never touched tracing layers before. But I think this may help you:

EnvFilter implements both the Layer and Filter traits, so it may be used for both global filtering and per-layer filtering, respectively. See the documentation on filtering with Layers for details.

https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html

So adding a filter with <custom-target>=<log-level> to your custom layer should work.

Example:

use tracing_subscriber::{fmt, EnvFilter, prelude::*};

fn main() {
    let custom_layer = fmt::layer()
        .with_writer(|| std::io::stderr())
        // EnvFilter as a Filter
        .with_filter(EnvFilter::try_new("custom_target=info").unwrap());

    tracing_subscriber::registry()
        // EnvFilter as a Layer
        .with(EnvFilter::try_new("info").unwrap())
        .with(fmt::layer()) // default
        .with(custom_layer) // custom
        .init();

    tracing::info!("default target");
    tracing::info!(target:"custom_target", "custom target");
}

Here the default layer is using the default writer to stdout, while the custom one is writing to stderr.