slog-rs / slog

Structured, contextual, extensible, composable logging for Rust
https://slog.rs/
Apache License 2.0
1.58k stars 95 forks source link

Clion log glitch #271

Open mikart143 opened 4 years ago

mikart143 commented 4 years ago

Hello! I noticed very strange bug. image My code:

    let log_path = "your_log_file_path.log";
    let file = OpenOptions::new()
        .create(true)
        .write(true)
        .truncate(true)
        .open(log_path)
        .unwrap();
    let file_decorator = slog_term::PlainDecorator::new(file);
    let file_drain = slog_term::FullFormat::new(file_decorator).build().fuse();
    let file_drain = slog_async::Async::new(file_drain).build().fuse();

    let term_decorator = slog_term::TermDecorator::new().build();
    let term_drain = slog_term::FullFormat::new(term_decorator).build().fuse();
    let term_drain = slog_async::Async::new(term_drain).build().fuse();
    let logger = slog::Logger::root(slog::Duplicate::new(file_drain, term_drain).fuse(), o!("version" => env!("CARGO_PKG_VERSION")));

    let _scope_guard = slog_scope::set_global_logger(logger);
    let _log_guard = slog_stdlog::init().unwrap();

    info!("Starting program...");

Logs in file looks good and also when I run app from linux terminal too. Clion: 2020.2.1

dpc commented 4 years ago

That's something to do with color handling, which is automatically not being done when logging to non-TTY device. I wonder if it's slog printing something weird, or just clion terminal emulator.

mikart143 commented 4 years ago

When using other loggers like fern, everything works perfect. I also turn on terminal emulation in clion. It looks like slog handle colors in the other way.

dpc commented 4 years ago

term crate is used for colors https://github.com/slog-rs/term/blob/5be2ff4895464b425c70a324302f9e9501d6a301/Cargo.toml#L22