Crate lovely_env_logger
source ·Expand description
A logger configured via environment variables which writes to standard error with nice colored output for log levels.
Example
extern crate lovely_env_logger;
#[macro_use] extern crate log;
fn main() {
lovely_env_logger::init_default();
trace!("a trace example");
debug!("deboogging");
info!("such information");
warn!("o_O");
error!("boom");
}
Run the program with the environment variable RUST_LOG=trace
.
Defaults
The defaults can be setup by calling init_default()
or
try_init_default()
at the start of the program.
Enable logging
This crate uses env_logger internally, so the same ways of enabling logs through an environment variable are supported.
Configuration through environment variables
Some options can be set through environment variables that have priority
over configuration set through the Config
structure.
The following options are set through environment variables named by
adding a suffix added to RUST_LOG
or the environment variable used to
filter the traces.
RUST_LOG_SHORT_LEVELS
Display levels on 3 characters to 1
. Display them as 5 characters
otherwise.
RUST_LOG_WITH_FILE_NAME
Display the file calling the log macro when set to 1
. Disable it otherwise.
RUST_LOG_WITH_LINE_NUMBER
Display the line number calling the log macro when set to 1
. Disable it otherwise.
RUST_LOG_WITH_PADDING
Display the log lines with padding after module name, when set to 1
. Disable it otherwise.
RUST_LOG_WITH_SYSTEM_TIMESTAMPS
Enable timestamps when set to 1
. Disable it otherwise.
Requires to be compiled with the humantime
feature.
RUST_LOG_WITH_RELATIVE_TIMESTAMPS
When set to 1
, display timestamps using the difference compared to the
previous log, or the date of log if the difference is too large.
Requires to be compiled with the reltime
feature.
Structs
Functions
env_logger::Builder
for further customization.