Struct env_logger::LogBuilder [] [src]

pub struct LogBuilder { /* fields omitted */ }

LogBuilder 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::{LogRecord, LogLevelFilter};
use env_logger::LogBuilder;

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

    let mut builder = LogBuilder::new();
    builder.format(format).filter(None, LogLevelFilter::Info);

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

    builder.init().unwrap();

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

Methods

impl LogBuilder
[src]

Initializes the log builder with defaults

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.

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.

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

See the module documentation for more details.

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 an error.

Build an env logger.