Closed hasezoey closed 1 year ago
There are now methods LoggerHandle::adapt_duplication_to_stderr
and LoggerHandle::adapt_duplication_to_stdout
which take a Duplicate
as parameter. Hope that fits :-)
sadly doing the following:
logger_handle
.adapt_duplication_to_stderr(flexi_logger::Duplicate::None)
.expect("Expected to be able to adapt duplication");
does not actually fully address my issue, i wanted a way to disable stderr
/ stdout
(or maybe any other specific target) output of logging regardless of if duplication
is activated (in my case logging to file, and so duplication is conditional - a cli argument)
currently if run without duplication, a Err
appears (for testing via .expect
):
thread 'main' panicked at 'Expected to be able to adapt duplication: NoFileLogger', crates/mh/src/main.rs:190:18
and in the case of the err being ignored, it still prints to the stderr, which messes up the TUI, my workaround for now is / was to not duplicate logging and if no file-logging is enabled to fully disable the logger via logger_handle.set_new_spec(LogSpecification::off());
Wouldn't it be sufficient for your case to not call logger_handle.adapt_duplication_to_stderr
if duplication was not configured in the first place?
well i just think the following is not really a great implementation:
info!("Disabling stderr logging");
if !cli_matches.log_options.log_to_file {
logger_handle.set_new_spec(LogSpecification::off());
} else {
let _ = logger_handle.adapt_duplication_to_stderr(flexi_logger::Duplicate::None);
}
when what i suggested in the original description would be:
info!("Disabling stderr logging");
logger_handle.disable(enum::stderr); // or any of the other proposed versions
but i guess this works for now
I currently have flexi_logger in a mixed cli / tui application and would like to disable output to
stderr
after the logger has already been configured and otherwise duplicate to both file and stderr.Why?
because stderr / stdout logging while being in a
tui-rs
(EnterAlternateScreen
) is not really the best experienceExample without any other things being rendered by
tui-rs
:currently as a workaround i will use the default behavior of "when a log_to_file is given, dont log to stderr" (no duplicate)
What would i like?
something along the lines of
or some kind of reconfigure akin to
reset_flw