diff --git a/Cargo.toml b/Cargo.toml index de1a78bf4fa..7a8cd8bc2c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ ethcore = { path = "ethcore" } ethcore-bytes = { path = "util/bytes" } ethcore-io = { path = "util/io" } ethcore-light = { path = "ethcore/light" } -ethcore-logger = { path = "logger" } +ethcore-logger = "1.12.0" ethcore-miner = { path = "miner" } ethcore-network = { path = "util/network" } ethcore-private-tx = { path = "ethcore/private-tx" } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 71c84a293f9..1683d678971 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -23,7 +23,7 @@ patricia-trie = { path = "../util/patricia_trie" } ethcore-crypto = { path = "crypto" } error-chain = { version = "0.11", default-features = false } ethcore-io = { path = "../util/io" } -ethcore-logger = { path = "../logger" } +ethcore-logger = "1.12.0" ethcore-miner = { path = "../miner" } ethcore-stratum = { path = "./stratum" } ethcore-transaction = { path = "./transaction" } diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index 0fa11aec84b..06bd2abe63a 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -14,7 +14,7 @@ ethcore = { path = ".." } ethcore-bytes = { path = "../../util/bytes" } ethcore-crypto = { path = "../crypto" } ethcore-io = { path = "../../util/io" } -ethcore-logger = { path = "../../logger" } +ethcore-logger = "1.12.0" ethcore-miner = { path = "../../miner" } ethcore-transaction = { path = "../transaction" } ethereum-types = "0.3" diff --git a/ethcore/stratum/Cargo.toml b/ethcore/stratum/Cargo.toml index bf967df504a..cee5fab36ec 100644 --- a/ethcore/stratum/Cargo.toml +++ b/ethcore/stratum/Cargo.toml @@ -18,4 +18,4 @@ parking_lot = "0.5" env_logger = "0.4" tokio-core = "0.1" tokio-io = "0.1" -ethcore-logger = { path = "../../logger" } +ethcore-logger = "1.12.0" diff --git a/ethcore/wasm/Cargo.toml b/ethcore/wasm/Cargo.toml index a0362955d1d..373d0de8522 100644 --- a/ethcore/wasm/Cargo.toml +++ b/ethcore/wasm/Cargo.toml @@ -11,5 +11,5 @@ parity-wasm = "0.27" libc = "0.2" pwasm-utils = "0.1" vm = { path = "../vm" } -ethcore-logger = { path = "../../logger" } +ethcore-logger = "1.12.0" wasmi = { version = "0.2" } diff --git a/ethcore/wasm/run/Cargo.toml b/ethcore/wasm/run/Cargo.toml index 514849f2afa..3c149ae4e85 100644 --- a/ethcore/wasm/run/Cargo.toml +++ b/ethcore/wasm/run/Cargo.toml @@ -12,7 +12,7 @@ ethjson = { path = "../../../json" } vm = { path = "../../vm" } wasm = { path = "../" } clap = "2.24" -ethcore-logger = { path = "../../../logger" } +ethcore-logger = "1.12.0" rustc-hex = "1" [features] diff --git a/logger/Cargo.toml b/logger/Cargo.toml deleted file mode 100644 index a1f793769c5..00000000000 --- a/logger/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -description = "Log implementation for Parity" -name = "ethcore-logger" -version = "1.12.0" -license = "GPL-3.0" -authors = ["Parity Technologies "] - -[dependencies] -log = "0.3" -env_logger = "0.4" -atty = "0.2" -lazy_static = "1.0" -regex = "0.2" -time = "0.1" -parking_lot = "0.5" -arrayvec = "0.4" -ansi_term = "0.10" diff --git a/logger/src/lib.rs b/logger/src/lib.rs deleted file mode 100644 index 863075a0e52..00000000000 --- a/logger/src/lib.rs +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2015-2017 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . - -//! Logger for parity executables - -extern crate ansi_term; -extern crate arrayvec; -extern crate atty; -extern crate env_logger; -extern crate log as rlog; -extern crate parking_lot; -extern crate regex; -extern crate time; - -#[macro_use] -extern crate lazy_static; - -mod rotating; - -use std::{env, thread, fs}; -use std::sync::{Weak, Arc}; -use std::io::Write; -use env_logger::LogBuilder; -use regex::Regex; -use ansi_term::Colour; -use parking_lot::Mutex; - -pub use rotating::{RotatingLogger, init_log}; - -#[derive(Debug, PartialEq, Clone)] -pub struct Config { - pub mode: Option, - pub color: bool, - pub file: Option, -} - -impl Default for Config { - fn default() -> Self { - Config { - mode: None, - color: !cfg!(windows), - file: None, - } - } -} - -lazy_static! { - static ref ROTATING_LOGGER : Mutex> = Mutex::new(Default::default()); -} - -/// Sets up the logger -pub fn setup_log(config: &Config) -> Result, String> { - use rlog::*; - - let mut levels = String::new(); - let mut builder = LogBuilder::new(); - // Disable info logging by default for some modules: - builder.filter(Some("ws"), LogLevelFilter::Warn); - builder.filter(Some("reqwest"), LogLevelFilter::Warn); - builder.filter(Some("hyper"), LogLevelFilter::Warn); - builder.filter(Some("rustls"), LogLevelFilter::Warn); - // Enable info for others. - builder.filter(None, LogLevelFilter::Info); - - if let Ok(lvl) = env::var("RUST_LOG") { - levels.push_str(&lvl); - levels.push_str(","); - builder.parse(&lvl); - } - - if let Some(ref s) = config.mode { - levels.push_str(s); - builder.parse(s); - } - - let isatty = atty::is(atty::Stream::Stderr); - let enable_color = config.color && isatty; - let logs = Arc::new(RotatingLogger::new(levels)); - let logger = logs.clone(); - let mut open_options = fs::OpenOptions::new(); - - let maybe_file = match config.file.as_ref() { - Some(f) => Some(open_options - .append(true).create(true).open(f) - .map_err(|_| format!("Cannot write to log file given: {}", f))?), - None => None, - }; - - let format = move |record: &LogRecord| { - let timestamp = time::strftime("%Y-%m-%d %H:%M:%S %Z", &time::now()).unwrap(); - - let with_color = if max_log_level() <= LogLevelFilter::Info { - format!("{} {}", Colour::Black.bold().paint(timestamp), record.args()) - } else { - let name = thread::current().name().map_or_else(Default::default, |x| format!("{}", Colour::Blue.bold().paint(x))); - format!("{} {} {} {} {}", Colour::Black.bold().paint(timestamp), name, record.level(), record.target(), record.args()) - }; - - let removed_color = kill_color(with_color.as_ref()); - - let ret = match enable_color { - true => with_color, - false => removed_color.clone(), - }; - - if let Some(mut file) = maybe_file.as_ref() { - // ignore errors - there's nothing we can do - let _ = file.write_all(removed_color.as_bytes()); - let _ = file.write_all(b"\n"); - } - logger.append(removed_color); - if !isatty && record.level() <= LogLevel::Info && atty::is(atty::Stream::Stdout) { - // duplicate INFO/WARN output to console - println!("{}", ret); - } - - ret - }; - - builder.format(format); - builder.init() - .and_then(|_| { - *ROTATING_LOGGER.lock() = Arc::downgrade(&logs); - Ok(logs) - }) - // couldn't create new logger - try to fall back on previous logger. - .or_else(|err| match ROTATING_LOGGER.lock().upgrade() { - Some(l) => Ok(l), - // no previous logger. fatal. - None => Err(format!("{:?}", err)), - }) -} - -fn kill_color(s: &str) -> String { - lazy_static! { - static ref RE: Regex = Regex::new("\x1b\\[[^m]+m").unwrap(); - } - RE.replace_all(s, "").to_string() -} - -#[test] -fn should_remove_colour() { - let before = "test"; - let after = kill_color(&Colour::Red.bold().paint(before)); - assert_eq!(after, "test"); -} - -#[test] -fn should_remove_multiple_colour() { - let t = format!("{} {}", Colour::Red.bold().paint("test"), Colour::White.normal().paint("again")); - let after = kill_color(&t); - assert_eq!(after, "test again"); -} diff --git a/logger/src/rotating.rs b/logger/src/rotating.rs deleted file mode 100644 index e67bdfaad0a..00000000000 --- a/logger/src/rotating.rs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2015-2017 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . - -//! Common log helper functions - -use std::env; -use rlog::LogLevelFilter; -use env_logger::LogBuilder; -use arrayvec::ArrayVec; - -use parking_lot::{RwLock, RwLockReadGuard}; - -lazy_static! { - static ref LOG_DUMMY: () = { - let mut builder = LogBuilder::new(); - builder.filter(None, LogLevelFilter::Info); - - if let Ok(log) = env::var("RUST_LOG") { - builder.parse(&log); - } - - if !builder.init().is_ok() { - println!("logger initialization failed!"); - } - }; -} - -/// Intialize log with default settings -pub fn init_log() { - *LOG_DUMMY -} - -const LOG_SIZE : usize = 128; - -/// Logger implementation that keeps up to `LOG_SIZE` log elements. -pub struct RotatingLogger { - /// Defined logger levels - levels: String, - /// Logs array. Latest log is always at index 0 - logs: RwLock>, -} - -impl RotatingLogger { - - /// Creates new `RotatingLogger` with given levels. - /// It does not enforce levels - it's just read only. - pub fn new(levels: String) -> Self { - RotatingLogger { - levels: levels, - logs: RwLock::new(ArrayVec::<[_; LOG_SIZE]>::new()), - } - } - - /// Append new log entry - pub fn append(&self, log: String) { - let mut logs = self.logs.write(); - if logs.is_full() { - logs.pop(); - } - logs.insert(0, log); - } - - /// Return levels - pub fn levels(&self) -> &str { - &self.levels - } - - /// Return logs - pub fn logs(&self) -> RwLockReadGuard> { - self.logs.read() - } - -} - -#[cfg(test)] -mod test { - use super::RotatingLogger; - - fn logger() -> RotatingLogger { - RotatingLogger::new("test".to_owned()) - } - - #[test] - fn should_return_log_levels() { - // given - let logger = logger(); - - // when - let levels = logger.levels(); - - // then - assert_eq!(levels, "test"); - } - - #[test] - fn should_return_latest_logs() { - // given - let logger = logger(); - - // when - logger.append("a".to_owned()); - logger.append("b".to_owned()); - - // then - let logs = logger.logs(); - assert_eq!(logs[0], "b".to_owned()); - assert_eq!(logs[1], "a".to_owned()); - assert_eq!(logs.len(), 2); - } -} - diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 731544a55f2..15613b4812c 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -42,7 +42,7 @@ ethcore-crypto = { path = "../ethcore/crypto" } ethcore-devtools = { path = "../devtools" } ethcore-io = { path = "../util/io" } ethcore-light = { path = "../ethcore/light" } -ethcore-logger = { path = "../logger" } +ethcore-logger = "1.12.0" ethcore-miner = { path = "../miner" } ethcore-private-tx = { path = "../ethcore/private-tx" } ethcore-sync = { path = "../ethcore/sync" } diff --git a/secret_store/Cargo.toml b/secret_store/Cargo.toml index fee832d069c..bae4855c740 100644 --- a/secret_store/Cargo.toml +++ b/secret_store/Cargo.toml @@ -26,7 +26,7 @@ url = "1.0" ethcore = { path = "../ethcore" } ethcore-bytes = { path = "../util/bytes" } ethcore-crypto = { path = "../ethcore/crypto" } -ethcore-logger = { path = "../logger" } +ethcore-logger = "1.12.0" ethcore-sync = { path = "../ethcore/sync" } ethcore-transaction = { path = "../ethcore/transaction" } ethereum-types = "0.3" diff --git a/util/journaldb/Cargo.toml b/util/journaldb/Cargo.toml index dea70bd6a43..f47ba02de0e 100644 --- a/util/journaldb/Cargo.toml +++ b/util/journaldb/Cargo.toml @@ -19,6 +19,6 @@ rlp = { path = "../rlp" } util-error = { path = "../error" } [dev-dependencies] -ethcore-logger = { path = "../../logger" } +ethcore-logger = "1.12.0" keccak-hash = { path = "../hash" } kvdb-memorydb = { path = "../kvdb-memorydb" } diff --git a/util/network-devp2p/Cargo.toml b/util/network-devp2p/Cargo.toml index f4889fe26d4..c3a3c4d398b 100644 --- a/util/network-devp2p/Cargo.toml +++ b/util/network-devp2p/Cargo.toml @@ -22,7 +22,7 @@ rustc-hex = "1.0" ethcore-io = { path = "../io", features = ["mio"] } ethcore-bytes = { path = "../bytes" } ethcore-crypto = { path = "../../ethcore/crypto" } -ethcore-logger = { path ="../../logger" } +ethcore-logger = "1.12.0" ethcore-network = { path = "../network" } ethereum-types = "0.3" ethkey = { path = "../../ethkey" } diff --git a/util/patricia_trie/Cargo.toml b/util/patricia_trie/Cargo.toml index 48b06b21463..a499530bd4c 100644 --- a/util/patricia_trie/Cargo.toml +++ b/util/patricia_trie/Cargo.toml @@ -16,7 +16,7 @@ hashdb = { version = "0.1.1", path = "../hashdb" } rlp = { version = "0.2.1", path = "../rlp" } triehash = { version = "0.1.0", path = "../triehash" } memorydb = { version = "0.1.0", path = "../memorydb" } -ethcore-logger = { version = "1.9.0", path = "../../logger" } +ethcore-logger = "1.12.0" [dev-dependencies] trie-standardmap = { path = "../trie-standardmap" } diff --git a/whisper/cli/Cargo.toml b/whisper/cli/Cargo.toml index 9aea1a8776e..2b0fb26ebcc 100644 --- a/whisper/cli/Cargo.toml +++ b/whisper/cli/Cargo.toml @@ -8,7 +8,7 @@ license = "GPL-3.0" [dependencies] ethcore-network-devp2p = { path = "../../util/network-devp2p" } ethcore-network = { path = "../../util/network" } -ethcore-logger = { path = "../../logger" } +ethcore-logger = "1.12.0" parity-whisper = { path = "../" } docopt = "0.8" serde = "1.0"