diff --git a/Cargo.lock b/Cargo.lock index 779220fb6..d1ef76816 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,7 @@ dependencies = [ "fdlimit 0.1.0", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fbf4b4ca6..2de097ad9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ log = "0.3" env_logger = "0.3" rustc-serialize = "0.3" docopt = "0.6" +time = "0.1" ctrlc = { git = "https://github.com/tomusdrw/rust-ctrlc.git" } clippy = { version = "0.0.44", optional = true } ethcore-util = { path = "util" } diff --git a/parity/main.rs b/parity/main.rs index e25933f2d..1b6a59a93 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -30,6 +30,7 @@ extern crate env_logger; extern crate ctrlc; extern crate fdlimit; extern crate daemonize; +extern crate time; #[cfg(feature = "rpc")] extern crate ethcore_rpc as rpc; @@ -38,7 +39,6 @@ use std::net::{SocketAddr}; use std::env; use std::process::exit; use std::path::PathBuf; -use rlog::{LogLevelFilter}; use env_logger::LogBuilder; use ctrlc::CtrlC; use util::*; @@ -112,6 +112,8 @@ struct Args { } fn setup_log(init: &Option) { + use rlog::*; + let mut builder = LogBuilder::new(); builder.filter(None, LogLevelFilter::Info); @@ -123,6 +125,15 @@ fn setup_log(init: &Option) { builder.parse(s); } + let format = |record: &LogRecord| { + let timestamp = time::strftime("%Y-%m-%d %H:%M:%S %Z", &time::now()).unwrap(); + if max_log_level() <= LogLevelFilter::Info { + format!("{}{}", timestamp, record.args()) + } else { + format!("{}{}:{}: {}", timestamp, record.level(), record.target(), record.args()) + } + }; + builder.format(format); builder.init().unwrap(); }