|
@@ -1,5 +1,6 @@
|
|
|
//! A logger that prints all messages with a readable output format.
|
|
|
|
|
|
+#[macro_use]
|
|
|
extern crate log;
|
|
|
extern crate time;
|
|
|
|
|
@@ -26,8 +27,20 @@ impl Log for SimpleLogger {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/// Initializes the global logger with a SimpleLogger instance with `max_log_level` set to
|
|
|
-/// the specified log level.
|
|
|
+/// Initializes the global logger with a SimpleLogger instance with
|
|
|
+/// `max_log_level` set to a specific log level.
|
|
|
+///
|
|
|
+/// ```
|
|
|
+/// # #[macro_use] extern crate log;
|
|
|
+/// # extern crate simple_logger;
|
|
|
+/// #
|
|
|
+/// # fn main() {
|
|
|
+/// simple_logger::init_with_level(log::LogLevel::Warn).unwrap();
|
|
|
+///
|
|
|
+/// warn!("This is an example message.");
|
|
|
+/// info!("This message will not be logged.");
|
|
|
+/// # }
|
|
|
+/// ```
|
|
|
pub fn init_with_level(log_level: LogLevel) -> Result<(), SetLoggerError> {
|
|
|
log::set_logger(|max_log_level| {
|
|
|
max_log_level.set(log_level.to_log_level_filter());
|
|
@@ -35,8 +48,18 @@ pub fn init_with_level(log_level: LogLevel) -> Result<(), SetLoggerError> {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-/// Initializes the global logger with a SimpleLogger instance with `max_log_level` set to
|
|
|
-/// `LogLevel::Trace`.
|
|
|
+/// Initializes the global logger with a SimpleLogger instance with
|
|
|
+/// `max_log_level` set to `LogLevel::Trace`.
|
|
|
+///
|
|
|
+/// ```
|
|
|
+/// # #[macro_use] extern crate log;
|
|
|
+/// # extern crate simple_logger;
|
|
|
+/// #
|
|
|
+/// # fn main() {
|
|
|
+/// simple_logger::init().unwrap();
|
|
|
+/// warn!("This is an example message.");
|
|
|
+/// # }
|
|
|
+/// ```
|
|
|
pub fn init() -> Result<(), SetLoggerError> {
|
|
|
init_with_level(LogLevel::Trace)
|
|
|
}
|