Implements a logger that can be configured via environment variables.
env_logger makes sense when used in executables (binary projects). Libraries should use the
log crate instead.
It must be added along with
log to the project dependencies:
 = "0.4.0" = "0.5.13"
env_logger must be initialized as early as possible in the project. After it's initialized, you can use the
log macros to do actual logging.
extern crate log; extern crate env_logger;
Then when running the executable, specify a value for the
environment variable that corresponds with the log messages you want to show.
Tests can use the
env_logger crate to see log messages generated during that test:
 = "0.4.0"  = "0.5.13"
extern crate log;
Assuming the module under test is called
my_lib, running the tests with the
RUST_LOG filtering to info messages from this module looks like:
; ; ;
env_logger::try_init() needs to be called in each test in which you
want to enable logging. Additionally, the default behavior of tests to
run in parallel means that logging output may be interleaved with test output.
Either run tests in a single thread by specifying
RUST_TEST_THREADS=1 or by
running one test by specifying its name as an argument to the test binaries as
directed by the
cargo test help docs:
; ; ;
Configuring log target
env_logger logs to stderr. If you want to log to stdout instead,
you can use the
Builder to change the log target:
use env; use ; let mut builder = new; builder.target; if var.is_ok builder.init;