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]
impl LogBuilder
pub fn new() -> LogBuilder
[src]
pub fn new() -> LogBuilder
Initializes the log builder with defaults
pub fn filter(
&mut self,
module: Option<&str>,
level: LogLevelFilter
) -> &mut Self
[src]
pub 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.
pub fn format<F: 'static>(&mut self, format: F) -> &mut Self where
F: Fn(&LogRecord) -> String + Sync + Send,
[src]
pub 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.
pub fn parse(&mut self, filters: &str) -> &mut Self
[src]
pub 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.
pub fn init(&mut self) -> Result<(), SetLoggerError>
[src]
pub 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.
pub fn build(&mut self) -> Logger
[src]
pub fn build(&mut self) -> Logger
Build an env logger.
Trait Implementations
Auto Trait Implementations
impl Send for LogBuilder
impl Send for LogBuilder
impl Sync for LogBuilder
impl Sync for LogBuilder