Expand description
A simple logger, optionally configured via environment variables which writes to standard error with nice colored output for log levels. It sets up logging with “sensible” defaults that make it ideal for running examples and tests on a crate of choice.
§Usage
Even though it has env
in the name, the sensible-env-logger
requires minimal configuration and setup to use:
#[macro_use] extern crate log;
fn main() {
sensible_env_logger::init!();
trace!("a trace example");
debug!("deboogging");
info!("such information");
warn!("o_O");
error!("boom");
}
Run the program and you should see all the log output for your crate.
Alternatively, run the program with the environment variables that control
the log level for your crate as well as external crates explicitly set,
like RUST_LOG=debug
and GLOBAL_RUST_LOG=error
.
§Defaults
The defaults can be setup by calling init!()
or try_init!()
at the start
of the program.
§Examples
You can check out sample usage of this crate in the examples/ folder in the project repo on GitHub.
§Readme Docs
You can find the crate’s readme documentation on the
crates.io page, or alternatively in the README.md
file on the GitHub project repo.
§Enable logging
This crate uses pretty_env_logger and env_logger internally, so the same ways of enabling logs through an environment variable are supported.
The sensible_env_logger
crate re-exports these crates, through the
pretty
and env
namespaces respectively.
Macros§
- init
- Initializes the global logger with a pretty, sensible env logger.
- init_
timed - Initializes the global logger with a timed pretty, sensible env logger.
- init_
timed_ local - Initializes the global logger with a “no-frills” local date/time pretty, sensible env logger.
- init_
timed_ local_ iso - Initializes the global logger with a local-timed pretty, sensible env logger.
- init_
timed_ short - Initializes the global logger with an “abbreviated” timed pretty, sensible env logger.
- safe_
init - Initializes the global logger with a pretty, sensible env logger.
- safe_
init_ timed - Initializes the global logger with a timed pretty, sensible env logger.
- safe_
init_ timed_ local - Initializes the global logger with a “no-frills” local date/time
pretty, sensible env logger.
See
init_timed_local!
for more info. - safe_
init_ timed_ local_ iso - Initializes the global logger with a local-timed pretty, sensible
env logger.
See
init_timed_local_iso!
for more info. - safe_
init_ timed_ short - Initializes the global logger with an “abbreviated” timed pretty, sensible
env logger.
See
init_timed_short!
for more info. - try_
init - Initializes the global logger with a pretty, sensible env logger.
- try_
init_ timed - Initializes the global logger with a timed pretty, sensible env logger.
- try_
init_ timed_ local - Initializes the global logger with a “no-frills” local date/time pretty, sensible env logger.
- try_
init_ timed_ local_ iso - Initializes the global logger with a local-timed pretty, sensible env logger.
- try_
init_ timed_ short - Initializes the global logger with an “abbreviated” timed pretty, sensible env logger.
Constants§
- ISO_FMT
- ISO 8601 / RFC 3339 date & time format.
- LOCAL_
TIME_ FMT - Local time zone format
- TIME_
ONLY_ FMT - Local time zone format (only time)
Functions§
- formatted_
local_ time_ builder_ fn - Returns a function (closure) that returns a formatted builder which adds local time to log messages, per a specified date/time format.
- try_
init_ custom_ env_ and_ builder - Initializes the global logger with a pretty, sensible env logger, with custom variable names and a custom builder function.