slog-rs / slog

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

No trace logs being output using slog_envlogger drain #303

Closed sbreatnach closed 2 years ago

sbreatnach commented 2 years ago

I've tried a few different ways to get log output via the slog_trace! macro using a slog_envlogger drain but nothing is coming through. This can be reproduced with the following project files:

Cargo.toml

[package]
name = "testlog"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "*"
slog = "*"
slog-scope = "*"
slog-async = "*"
slog-stdlog = "*"
slog-term = "*"
slog-envlogger = "*"

src/main.rs (adapted from https://github.com/slog-rs/envlogger/blob/master/examples/proper.rs)

#[macro_use]
extern crate slog;
#[macro_use]
extern crate slog_scope;
#[macro_use]
extern crate log;

use slog::Drain;

fn main() {
    let drain =
        slog_async::Async::default(
        slog_envlogger::new(
        slog_term::CompactFormat::new(
            slog_term::TermDecorator::new()
            .stderr().build()
            ).build().fuse()
        ));

    let root_logger = slog::Logger::root(drain.fuse(),
                                         slog_o!("build" => "8jdkj2df", "version" => "0.1.5"));

    slog_stdlog::init().unwrap();

    slog_scope::scope(&root_logger, || {

        slog_error!(root_logger, "slog error");
        error!("log error");
        slog_info!(root_logger, "slog info");
        info!("log info");
        slog_trace!(root_logger, "slog trace");
        trace!("log trace");
    });
}

Using cargo 1.57.0 (b2e52d7ca 2021-10-21), I build and run with env RUST_LOG=trace cargo run. All output will appear as expected, except for "slog trace".

Is there something I'm missing, some configuration option that's required?

dpc commented 2 years ago

Probably https://docs.rs/slog/latest/slog/#notable-details

Techcable commented 2 years ago

Yes! Please make sure you have the feature flags set correctly to enable/disable trace logging.

This has bitten me a number of times (even in the same codebase). It's definitely not an uncommon problem even for contributors 😉

If you still encounter this problem after fixing 5hr appropriate feature flags, please leave a comment and we'll reopen this :)

dpc commented 2 years ago

It was a bad idea. :D

I was thinking if we could deprecate or something.