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]

[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));
}

[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));
}

[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);
}

[src]

Checks if this record matches the configured filter.

Trait Implementations

impl Debug for Logger
[src]

[src]

Formats the value using the given formatter.

impl Log for Logger
[src]

[src]

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

[src]

Logs the Record. Read more

[src]

Flushes any buffered records.