[−][src]Crate log_reroute
Crate to reroute logging messages at runtime.
The log
logging facade allows to set only a single
destination during the whole lifetime of program. If you want to change the logging destination
multiple times, you can use Reroute
(either directly, or through the
init
and reroute
functions).
This may be useful if you want to log to stderr
before you know where the main logs will go.
extern crate fern; #[macro_use] extern crate log; extern crate log_reroute; extern crate tempfile; use fern::Dispatch; use log::LevelFilter; fn main() { log::set_max_level(LevelFilter::Off); info!("This log message goes nowhere"); log_reroute::init().unwrap(); info!("Still goes nowhere"); // Log to stderr let early_logger = Dispatch::new().chain(std::io::stderr()).into_log().1; log_reroute::reroute_boxed(early_logger); info!("This one goes to stderr"); // Load file name from config and log to that file let file = tempfile::tempfile().unwrap(); let logger = Dispatch::new().chain(file).into_log().1; log_reroute::reroute_boxed(logger); info!("And this one to the file"); // Stop logging log_reroute::reroute(log_reroute::Dummy); }
Structs
Dummy | A logger that doesn't log. |
Reroute | A logging proxy. |
Statics
REROUTE | A global |
Functions
init | |
reroute | Changes the slave of the global |
reroute_boxed | Changes the slave of the global |