An easy-to-configure and flexible logger that writes logs to stderr and/or to files. It allows custom logline formats, and it allows changing the log specification at runtime. It also allows defining additional log streams, e.g. for alert or security messages.
#![feature(test)]externcrate test;externcrate flexi_logger;#[macro_use]externcrate log;useflexi_logger::Logger;usetest::Bencher;#[bench]fnb10_no_logger_active(b:&mut Bencher){
b.iter(use_error);}#[bench]fnb20_initialize_logger(_: &mut Bencher){Logger::with_str("info").log_to_file().directory("log_files").start_reconfigurable().unwrap_or_else(|e|panic!("Logger initialization failed with {}", e));}#[bench]fnb30_relevant_logs(b:&mut Bencher){
b.iter(use_error);}#[bench]fnb40_suppressed_logs(b:&mut Bencher){
b.iter(use_trace);}fnuse_error(){for_in1..100{error!("This is an error message");}}fnuse_trace(){for_in1..100{trace!("This is a trace message");}}