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
Logger::new()
or the associated Builder
and install it with the
log
crate directly.
Methods
impl Logger
[src]
fn new() -> Logger
[src]
Creates a new env logger by parsing the RUST_LOG
environment variable.
The returned logger can be passed to the log
crate
for initialization as a global logger.
If you do not need to interact directly with the Logger
, you should
prefer the init()
or try_init()
methods, which
construct a Logger
and configure it as the default logger.
Example
extern crate log; extern crate env_logger; use std::env; use env_logger::Logger; fn main() { let logger = Logger::new(); log::set_max_level(logger.filter()); log::set_boxed_logger(Box::new(logger)); }
fn from_env(env: &str) -> Logger
[src]
Creates a new env logger by parsing the environment variable with the given name.
This is identical to the new()
constructor, except it allows the
name of the environment variable to be customized. For additional
customization, use the Builder
type instead.
The returned logger can be passed to the log
crate
for initialization as a global logger.
Example
extern crate log; extern crate env_logger; use std::env; use env_logger::Logger; fn main() { let logger = Logger::from_env("MY_LOG"); log::set_max_level(logger.filter()); log::set_boxed_logger(Box::new(logger)); }
fn filter(&self) -> LevelFilter
[src]
Returns the maximum LevelFilter
that this env logger instance is
configured to output.
Example
extern crate log; extern crate env_logger; use log::LevelFilter; use env_logger::Builder; fn main() { let mut builder = Builder::new(); builder.filter(Some("module1"), LevelFilter::Info); builder.filter(Some("module2"), LevelFilter::Error); let logger = builder.build(); assert_eq!(logger.filter(), LevelFilter::Info); }
fn matches(&self, record: &Record) -> bool
[src]
Checks if this record matches the configured filter.