#[macro_use]extern crate log;extern crate env_logger; extern crate time; use std::env;use log::{LogRecord, LogLevelFilter};use env_logger::LogBuilder; fn now() -> String { time::strftime("%Y-%m-%d %H:%M:%S", &time::now()).unwrap()} fn main() { let format = |record: &LogRecord| { format!("{} {} {}:{} {}", now(), record.level(), record.location().file(), record.location().line(), record.args()) }; let mut builder = LogBuilder::new(); builder.format(format).filter(None, LogLevelFilter::Info); if env::var("RUST_LOG").is_ok() { builder.parse(&env::var("RUST_LOG").unwrap()); } builder.init().unwrap(); error!("error message"); warn!("warn message"); info!("info message"); debug!("debug message"); trace!("trace message"); info!("done.")} // output ://2016-06-25 16:49:04 ERROR examples/ex01.rs:41 error message//2016-06-25 16:49:04 WARN examples/ex01.rs:42 warn message//2016-06-25 16:49:04 INFO examples/ex01.rs:43 info message//2016-06-25 16:49:04 INFO examples/ex01.rs:47 done.