slog
slog copied to clipboard
Clion log glitch
Hello!
I noticed very strange bug.
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
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.
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.
term
crate is used for colors https://github.com/slog-rs/term/blob/5be2ff4895464b425c70a324302f9e9501d6a301/Cargo.toml#L22