• 0 Posts
  • 3 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle

  • 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).


  • 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.