Browse Source

Add doctests

Sam Clements 10 years ago
parent
commit
abb2f5300f
2 changed files with 27 additions and 13 deletions
  1. 27 4
      src/lib.rs
  2. 0 9
      tests/lib.rs

+ 27 - 4
src/lib.rs

@@ -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)
 }

+ 0 - 9
tests/lib.rs

@@ -1,9 +0,0 @@
-#[macro_use]
-extern crate log;
-extern crate simple_logger;
-
-#[test]
-fn log_message() {
-    simple_logger::init().unwrap();
-    warn!("This is an example message.");
-}