Drakulix/simplelog.rs

How to set a log level on each logger separately on the fly ?

dabrain34 opened this issue · 3 comments

If I understood correctly this is not available, so what would be the option to set the log level for a given write logger in a combined logger defined as this:

    simplelog::CombinedLogger::init(vec![
        WriteLogger::new(
            translate_to_simple_logger(LogLevel::Trace),
            Config::default(),
            File::create(log_file).unwrap(),
        ),
        WriteLogger::new(
            translate_to_simple_logger(LogLevel::Debug),
            Config::default(),
            WriteAdapter {
                sender,
                buffer: String::from(""),
            },
        ),
        TermLogger::new(
            LevelFilter::Info,
            Config::default(),
            TerminalMode::Mixed,
            ColorChoice::Auto,
        ),
    ])
    .unwrap();

It seems that I can do it with log::set_max_level but I'd like to set it up only for the second one and keep the other ones at full log

This feature should be available, see the example from the README:

CombinedLogger::init(
        vec![
            TermLogger::new(LevelFilter::Warn, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
            WriteLogger::new(LevelFilter::Info, Config::default(), File::create("my_rust_binary.log").unwrap()),
        ]
    ).unwrap();

The first logger logs Errors and Warnings, the second additionally includes Info.

yes but how could I change it on the fly ? I mean I connect the log to a ListView and I'd like to change the value in a settings panel to enable or disable some log levels without restarting the application.

Here is an example: https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio/-/merge_requests/25

yes but how could I change it on the fly ? I mean I connect the log to a ListView and I'd like to change the value in a settings panel to enable or disable some log levels without restarting the application.

Runtime configuration is not in scope of simplelog, it's config is set one time at start up.
If you need this feature, you should take a look into more fully-featured logging frameworks like fern, slog or tracing.