Log formatting

This commit is contained in:
arkpar 2016-02-23 20:14:37 +01:00
parent 6fe189cbd9
commit 40f908a499
3 changed files with 14 additions and 1 deletions

1
Cargo.lock generated
View File

@ -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]]

View File

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

View File

@ -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<String>) {
use rlog::*;
let mut builder = LogBuilder::new();
builder.filter(None, LogLevelFilter::Info);
@ -123,6 +125,15 @@ fn setup_log(init: &Option<String>) {
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();
}