//! Crate to reroute logging messages at runtime.
//!
//! The [`log`](https://crates.io/crates/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`](struct.Reroute.html) (either directly, or through the
//! [`init`](fn.init.html) and [`reroute`](fn.reroute.html) functions).
//!
//! This may be useful if you want to log to `stderr` before you know where the main logs will go.
//!
//! ```rust
//! 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);
//! }
//! ```
extern crate arc_swap;
extern crate log;
extern crate once_cell;
use Arc;
use ArcSwap;
use ;
use Lazy;
/// A logger that doesn't log.
///
/// This is used to stub out the reroute in case no other log is set.
;
/// A logging proxy.
///
/// This logger forwards all calls to currently configured slave logger.
///
/// The log routing is implemented in a lock-less and wait-less manner. While not necessarily faster
/// than using a mutex (unless there's a lot of contention and the slave logger also doesn't lock),
/// it makes it usable in some weird places (like a signal handler).
///
/// The rerouting (eg. changing the slave) is lock-less, but may have to wait for current logging
/// calls to end and concurrent reroutes will block each other.
///
/// # Note
///
/// When switching a logger, no care is taken to pair logging calls. In other words, it is possible
/// a message is written to the old logger and the new logger is flushed. This shouldn't matter in
/// practice, since a logger should flush itself once it is dropped.
/// A global [`Reroute`](struct.Reroute.html) object.
///
/// This one is manipulated by the global functions:
///
/// * [`init`](fn.init.html)
/// * [`reroute`](fn.reroute.html)
/// * [`reroute_boxed`](fn.reroute_boxed.html)
pub static REROUTE: = sync_lazy!;
/// Installs the global [`Reroute`](struct.Reroute.html) instance into the
/// [`log`](https://crates.io/crates/log) facade.
///
/// Note that the default slave is [`Dummy`](struct.Dummy.html) and you need to call
/// [`reroute`](fn.reroute.html) or [`reroute_boxed`](fn.reroute_boxed.html).
/// Changes the slave of the global [`Reroute`](struct.Reroute.html) instance.
///
/// If you have a boxed logger, use [`reroute_boxed`](fn.reroute_boxed.html).
/// Changes the slave of the global [`Reroute`](struct.Reroute.html) instance.