Confusion with using RUST_LOG


#1

Hello, I’m trying to use the log crate to output with the debug! macro and I’m having some difficulties getting it working. If I include extern crate log in my lib and use debug!(“some string”), everything builds but I get no output from the debug.

For a cargo project named “test”, I have my path variable set as RUST_LOG=test with no output. If I instead set the variable to RUST_LOG=debug I get the debug logs from cargo and rustc themselves when I run cargo build, so I know I have the tools built properly to enable this feature. Using this setting when I run my binary seems to still give me no output. Am I misunderstanding how the RUST_LOG variable is supposed to be set here?

My code is as simple as it can be:

fn main() {
debug!(“This is my test {}”, “message”);
}


#2

log isn’t a feature-complete crate, you need to add another crate to your executable to use it.


#3

log is a facade (common interface) for logging. To actually produce log output you’ll need to use a logger. The log README notes a few options:

In order to produce log output executables have to use a logger implementation compatible with the facade.
There are many available implementations to chose from, here are some of the most popular ones:

If in doubt env_logger is a good place to start.


#4

That makes sense, not sure how I managed to miss that. Got it working now, thanks for the help folks