Struct env_logger::Logger[][src]

pub struct Logger { /* fields omitted */ }

The env logger.

This struct implements the Log trait from the log crate, which allows it to act as a logger.

The init(), try_init(), Builder::init() and Builder::try_init() methods will each construct a Logger and immediately initialize it as the default global logger.

If you'd instead need access to the constructed Logger, you can use the associated Builder and install it with the log crate directly.


impl Logger

Creates the logger from the environment.

The variables used to read configuration from can be tweaked before passing in.


Create a logger reading the log filter from an environment variable called MY_LOG:

use env_logger::Logger;

let logger = Logger::from_env("MY_LOG");

Create a logger using the MY_LOG variable for filtering and MY_LOG_STYLE for whether or not to write styles:

use env_logger::{Logger, Env};

let env = Env::new().filter_or("MY_LOG", "info").write_style_or("MY_LOG_STYLE", "always");

let logger = Logger::from_env(env);

Creates the logger from the environment using default variable names.

This method is a convenient way to call from_env(Env::default()) without having to use the Env type explicitly. The logger will use the default environment variables.


Creates a logger using the default environment variables:

use env_logger::Logger;

let logger = Logger::from_default_env();

Returns the maximum LevelFilter that this env logger instance is configured to output.

Checks if this record matches the configured filter.

Trait Implementations

impl Debug for Logger

Formats the value using the given formatter. Read more

impl Log for Logger

Determines if a log message with the specified metadata would be logged. Read more

Logs the Record. Read more

Flushes any buffered records.

Auto Trait Implementations

impl Send for Logger

impl Sync for Logger