Giter VIP home page Giter VIP logo

Comments (3)

kaffarell avatar kaffarell commented on August 17, 2024

Could you post a snippet? Also checkout https://docs.rs/tracing-subscriber/latest/tracing_subscriber/reload/index.html#examples. This should be possible if I understand your issue correctly.

from tracing.

wuanzhuan avatar wuanzhuan commented on August 17, 2024

@kaffarell I use the envfilter. Because of it can easy to "and" tow filter. I use one global level filter and some target filter in a env filter.
And i just want to modify the global level filter or one target filter. how to do it?

    // trace init:
    let subscriber = tracing_fmt::fmt()
        .with_timer(tracing_fmt::time::LocalTime::rfc_3339())
        .with_file(true)
        .with_line_number(true)
        .with_writer(non_blocking)
        .with_ansi(false)
        .with_env_filter(format!("info,sys_monitor::event_trace::stack_walk=debug")) // env filter
        .with_filter_reloading();
    let reload_handle = subscriber.reload_handle();
    subscriber.init();

//==================
   
   // How to modify env filter like this:
   reload_handle.modify(|filter| *filter = filter::LevelFilter::DEBUG);

from tracing.

kaffarell avatar kaffarell commented on August 17, 2024

AFAIK editing the EnvFilter directly is not possible, but you can create a layer with multiple filters! For example something like this should work:

    let filter = filter::LevelFilter::WARN;
    let (filter, reload_handle) = reload::Layer::new(filter);

    let layer = tracing_subscriber::fmt::layer()
        .with_timer(tracing_subscriber::fmt::time::LocalTime::rfc_3339())
        .with_file(true)
        .with_line_number(true)
        .with_ansi(false)
        .with_filter(EnvFilter::new("trace,sys_monitor::event_trace::stack_walk=debug"))
        .with_filter(filter);

    tracing_subscriber::registry().with(layer).init();

    let _ = reload_handle.modify(|filter| *filter = filter::LevelFilter::DEBUG);

from tracing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.