'Change max log level on the fly with the tracing crate

as a developer I would like to adjust the log level on the fly, for example, I don't want to log debug log when everything is going fine, but when something happened, I would like to adjust the log level without restart the application by develop an control plane api to change the log level, I check the doc and can't find an example there. so I want to know if it is possible to do that.

    let subscriber = tracing_subscriber::fmt().with_max_level(Level::INFO).finish();
 
    tracing::subscriber::set_global_default(subscriber);
//how can I change the max_level of subscriber after it was initialised?
    info!("some log message");


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source