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]
fn new() -> LogBuilder
Initializes the log builder with defaults
fn filter(&mut self, module: Option<&str>, level: LogLevelFilter) -> &mut Self
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.
fn format<F: 'static>(&mut self, format: F) -> &mut Self where F: Fn(&LogRecord) -> String + Sync + Send
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.
fn parse(&mut self, filters: &str) -> &mut Self
Parses the directives string in the same form as the RUST_LOG environment variable.
See the module documentation for more details.
fn init(&mut self) -> Result<(), SetLoggerError>
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.
fn build(&mut self) -> Logger
Build an env logger.