Struct env_logger::Builder [] [src]

pub struct Builder { /* fields omitted */ }

Builder acts as builder for initializing the Logger. It can be used to customize the log format, change the enviromental variable used to provide the logging directives and also set the default log level filter.

Example

#[macro_use]
extern crate log;
extern crate env_logger;

use std::env;
use log::{Record, LevelFilter};
use env_logger::Builder;

fn main() {
    let format = |record: &Record| {
        format!("{} - {}", record.level(), record.args())
    };

    let mut builder = Builder::new();
    builder.format(format).filter(None, LevelFilter::Info);

    if env::var("RUST_LOG").is_ok() {
       builder.parse(&env::var("RUST_LOG").unwrap());
    }

    builder.init();

    error!("error message");
    info!("info message");
}

Methods

impl Builder
[src]

[src]

Initializes the log builder with defaults

[src]

Adds filters to the logger

The given module (if any) will log at most the specified level provided. If no module is provided then the filter will apply to all log messages.

[src]

Sets the format function for formatting the log output.

This function is called on each record logged to produce a string which is actually printed out.

[src]

Sets the target for the log output.

Env logger can log to either stdout or stderr. The default is stderr.

[src]

Parses the directives string in the same form as the RUST_LOG environment variable.

See the module documentation for more details.

[src]

Initializes the global logger with an env logger.

This should be called early in the execution of a Rust program, and the global logger may only be initialized once. Future initialization attempts will return error.

[src]

Initializes the global logger with an env logger.

This should be called early in the execution of a Rust program, and the global logger may only be initialized once. Future initialization attempts will panic.

[src]

Build an env logger.