1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
/*! ## filtering Use the ENV variable `RUST_LOG` with `module_name=level` `RUST_LOG="tokio=warn,my_module=info,my_module::inner=trace"` A default level can be provided with just ***level***. e.g. `RUST_LOG=trace` will enable `trace` for all modules. You can disable specific modules/crates by using the `off` level ## optional features * `time` allows formatting a UTC timestamp with the [`time`](time) crate. * see the formatting table [here](https://docs.rs/time/0.2.10/time/#formatting) [time]: https://docs.rs/time */ #[cfg(all(doctest))] doc_comment::doctest!("../README.md"); #[doc(inline)] pub use termcolor::Color; /// Initialize the logger /// /// ```rust /// use alto_logger::{ /// options::{ColorConfig, StyleConfig, TimeConfig}, /// Options, /// TermLogger, /// }; /// alto_logger::init( /// TermLogger::new( /// Options::default() /// .with_style(StyleConfig::SingleLine) // Default is a MultiLine output /// .with_time(TimeConfig::relative_now()) // Default is no timestamp /// .with_color(ColorConfig::only_levels()), // Default is full color /// ) /// .unwrap(), /// ) /// .unwrap() /// ``` /// /// And using the shorthands /// ```rust,ignore /// use alto_logger::*; /// MultiLogger::new() /// .with(TermLogger::default()) /// // date_time_format requires the `time` feature /// .with(FileLogger::append(TimeConfig::date_time_format("%c"), "output.log").unwrap()) /// .init() /// .expect("init logger"); /// ``` /// pub fn init(logger: impl log::Log + 'static) -> Result<(), Error> { // enables trace for all // TODO this is wrong log::set_max_level(log::LevelFilter::Trace); log::set_boxed_logger(Box::new(logger)).map_err(Error::SetLogger) } /// Convenience function to create a default terminal logger /// /// This defaults to using: /// * no timestamp /// * default colors /// * multi-line output pub fn init_term_logger() -> Result<(), Error> { TermLogger::new(Options::default()).and_then(init) } mod error; mod filters; mod loggers; pub mod options; #[doc(inline)] pub use options::*; pub use loggers::*; #[doc(inline)] pub use error::Error;