djugei / indicatif-log-bridge

bridges the log crate and indicatif to stop the progress bars and log lines from mixing up
8 stars 2 forks source link

Is this compatible with flex_logger? #2

Closed moranbw closed 11 months ago

moranbw commented 11 months ago

Is this compatible with flexi_logger?

I try to use it like this:

    let _logger = Logger::try_with_str("debug")
        .unwrap()
        .format(opt_format)
        .log_to_file(FileSpec::default().directory("./log"))
        .duplicate_to_stderr(Duplicate::Error)
        .write_mode(WriteMode::BufferAndFlush)
        .start()
        .unwrap();

    let multi_progress = MultiProgress::new();

    LogWrapper::new(multi_progress.clone(), _logger)
        .try_init()
        .unwrap();

I'm getting the following error:

error[E0277]: the trait bound `LoggerHandle: log::Log` is not satisfied
   --> src\main.rs:127:5
    |
127 |     LogWrapper::new(multi_progress.clone(), _logger)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `log::Log` is not implemented for `LoggerHandle`
    |
    = help: the following other types implement trait `log::Log`:
              &T
              Arc<T>
              Box<T>
              LogWrapper<L>
note: required by a bound in `LogWrapper`
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\indicatif-log-bridge-0.2.2\src\lib.rs:43:26
    |
43  | pub struct LogWrapper<L: Log> {
    |                          ^^^ required by this bound in `LogWrapper`

I also tried to separate out the flexi_logger call of .start() so that I had a Logger rather than LoggerHandle, but that did not seem to help. Any guidance is greatly appreciated!

djugei commented 11 months ago

having a quick look into flexi_loggers source code tells me that the only thing in that crate that implements the Log trait is the private struct FlexiLogger, so unless that get exposed publicly the crates are not compatible. Maybe file an issue against flexi_logger.

additionally it would have the issue of suspending output on the terminal even if some lines are only written to a file, not the terminal.

if you are building a complex user interface on the terminal maybe a tui-crate is also an option.

moranbw commented 11 months ago

Thanks for the response! It's a pretty simple CLI app, so a TUI may be overkill. Will investigate other log crates to see if something is more compatible.