Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Update log -> 0.4, env_logger -> 0.5. (#9294)
Browse files Browse the repository at this point in the history
* Rename a few types & methods.

* Change `(Log)Builder::format` (closure) arg.
  • Loading branch information
c0gent authored and andresilva committed Aug 9, 2018
1 parent b28e742 commit e590874
Show file tree
Hide file tree
Showing 41 changed files with 168 additions and 110 deletions.
144 changes: 101 additions & 43 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
blooms-db = { path = "util/blooms-db" }
log = "0.3"
env_logger = "0.4"
log = "0.4"
env_logger = "0.5"
rustc-hex = "1.0"
docopt = "0.8"
clap = "2"
Expand Down
2 changes: 1 addition & 1 deletion ethash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[lib]

[dependencies]
log = "0.3"
log = "0.4"
keccak-hash = { git = "https://github.com/paritytech/parity-common" }
primal = "0.2.3"
parking_lot = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ evm = { path = "evm" }
heapsize = "0.4"
itertools = "0.5"
lazy_static = "1.0"
log = "0.3"
log = "0.4"
lru-cache = "0.1"
num = { version = "0.1", default-features = false, features = ["bigint"] }
num_cpus = "1.2"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bit-set = "0.4"
ethereum-types = "0.3"
heapsize = "0.4"
lazy_static = "1.0"
log = "0.3"
log = "0.4"
vm = { path = "../vm" }
keccak-hash = { git = "https://github.com/paritytech/parity-common" }
parking_lot = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "1.12.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
log = "0.3"
log = "0.4"
ethcore = { path = ".."}
parity-bytes = { git = "https://github.com/paritytech/parity-common" }
ethcore-transaction = { path = "../transaction" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/node_filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ethcore = { path = ".."}
ethcore-network = { path = "../../util/network" }
ethcore-network-devp2p = { path = "../../util/network-devp2p" }
ethereum-types = "0.3"
log = "0.3"
log = "0.4"
parking_lot = "0.6"
ethabi = "5.1"
ethabi-derive = "5.0"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/private-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ethkey = { path = "../../ethkey" }
fetch = { path = "../../util/fetch" }
futures = "0.1"
keccak-hash = { git = "https://github.com/paritytech/parity-common" }
log = "0.3"
log = "0.4"
parking_lot = "0.6"
patricia-trie = { git = "https://github.com/paritytech/parity-common" }
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ethcore-io = { path = "../../util/io" }
ethcore-private-tx = { path = "../private-tx" }
ethcore-sync = { path = "../sync" }
kvdb = { git = "https://github.com/paritytech/parity-common" }
log = "0.3"
log = "0.4"
stop-guard = { path = "../../util/stop-guard" }
trace-time = { path = "../../util/trace-time" }

Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ fn enact(
ancestry: &mut Iterator<Item=ExtendedHeader>,
) -> Result<LockedBlock, Error> {
{
if ::log::max_log_level() >= ::log::LogLevel::Trace {
if ::log::max_level() >= ::log::Level::Trace {
let s = State::from_existing(db.boxed_clone(), parent.state_root().clone(), engine.account_start_nonce(parent.number() + 1), factories.clone())?;
trace!(target: "enact", "num={}, root={}, author={}, author_balance={}\n",
header.number(), s.root(), header.author(), s.balance(&header.author())?);
Expand Down Expand Up @@ -659,7 +659,7 @@ mod tests {
let transactions = transactions?;

{
if ::log::max_log_level() >= ::log::LogLevel::Trace {
if ::log::max_level() >= ::log::Level::Trace {
let s = State::from_existing(db.boxed_clone(), parent.state_root().clone(), engine.account_start_nonce(parent.number() + 1), factories.clone())?;
trace!(target: "enact", "num={}, root={}, author={}, author_balance={}\n",
header.number(), s.root(), header.author(), s.balance(&header.author())?);
Expand Down
4 changes: 2 additions & 2 deletions ethcore/stratum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ keccak-hash = { git = "https://github.com/paritytech/parity-common" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
jsonrpc-macros = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
jsonrpc-tcp-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
log = "0.3"
log = "0.4"
parking_lot = "0.6"

[dev-dependencies]
env_logger = "0.4"
env_logger = "0.5"
tokio-core = "0.1"
tokio-io = "0.1"
ethcore-logger = { path = "../../logger" }
4 changes: 2 additions & 2 deletions ethcore/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ keccak-hasher = { path = "../../util/keccak-hasher" }
triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" }
kvdb = { git = "https://github.com/paritytech/parity-common" }
macros = { path = "../../util/macros" }
log = "0.3"
env_logger = "0.4"
log = "0.4"
env_logger = "0.5"
rand = "0.4"
heapsize = "0.4"
semver = "0.9"
Expand Down
18 changes: 9 additions & 9 deletions ethcore/sync/src/tests/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use {SyncConfig, WarpSync};

#[test]
fn two_peers() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(3);
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
Expand All @@ -33,7 +33,7 @@ fn two_peers() {

#[test]
fn long_chain() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(2);
net.peer(1).chain.add_blocks(50000, EachBlockWith::Nothing);
net.sync();
Expand All @@ -43,7 +43,7 @@ fn long_chain() {

#[test]
fn status_after_sync() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(3);
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
Expand All @@ -63,7 +63,7 @@ fn takes_few_steps() {

#[test]
fn empty_blocks() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(3);
for n in 0..200 {
let with = if n % 2 == 0 { EachBlockWith::Nothing } else { EachBlockWith::Uncle };
Expand All @@ -77,7 +77,7 @@ fn empty_blocks() {

#[test]
fn forked() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(3);
net.peer(0).chain.add_blocks(30, EachBlockWith::Uncle);
net.peer(1).chain.add_blocks(30, EachBlockWith::Uncle);
Expand All @@ -98,7 +98,7 @@ fn forked() {

#[test]
fn forked_with_misbehaving_peer() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(3);

let mut alt_spec = ::ethcore::spec::Spec::new_test();
Expand All @@ -122,7 +122,7 @@ fn forked_with_misbehaving_peer() {

#[test]
fn net_hard_fork() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let ref_client = TestBlockChainClient::new();
ref_client.add_blocks(50, EachBlockWith::Uncle);
{
Expand All @@ -141,7 +141,7 @@ fn net_hard_fork() {

#[test]
fn restart() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(3);
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
Expand Down Expand Up @@ -255,7 +255,7 @@ fn high_td_attach() {

#[test]
fn disconnect_on_unrelated_chain() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut net = TestNet::new(2);
net.peer(0).chain.set_history(Some(20));
net.peer(1).chain.set_history(Some(20));
Expand Down
2 changes: 1 addition & 1 deletion ethcore/sync/src/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl SnapshotService for TestSnapshotService {

#[test]
fn snapshot_sync() {
::env_logger::init().ok();
::env_logger::try_init().ok();
let mut config = SyncConfig::default();
config.warp_sync = WarpSync::Enabled;
let mut net = TestNet::new_with_config(5, config);
Expand Down
2 changes: 1 addition & 1 deletion ethcore/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parity-bytes = { git = "https://github.com/paritytech/parity-common" }
ethereum-types = "0.3"
patricia-trie = { git = "https://github.com/paritytech/parity-common" }
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
log = "0.3"
log = "0.4"
common-types = { path = "../types" }
ethjson = { path = "../../json" }
rlp = { git = "https://github.com/paritytech/parity-common" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
byteorder = "1.0"
ethereum-types = "0.3"
log = "0.3"
log = "0.4"
parity-wasm = "0.31"
libc = "0.2"
pwasm-utils = "0.2.2"
Expand Down
2 changes: 1 addition & 1 deletion ethkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parity-crypto = { git = "https://github.com/paritytech/parity-common" }
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
ethereum-types = "0.3"
lazy_static = "1.0"
log = "0.3"
log = "0.4"
mem = { path = "../util/mem" }
parity-wordlist = "1.2"
quick-error = "1.2.2"
Expand Down
2 changes: 1 addition & 1 deletion ethkey/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
docopt = "0.8"
env_logger = "0.4"
env_logger = "0.5"
ethkey = { path = "../" }
panic_hook = { path = "../../util/panic_hook" }
parity-wordlist="1.2"
Expand Down
2 changes: 1 addition & 1 deletion ethkey/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl DisplayMode {

fn main() {
panic_hook::set_abort();
env_logger::init().expect("Logger initialized only once.");
env_logger::try_init().expect("Logger initialized only once.");

match execute(env::args()) {
Ok(ok) => println!("{}", ok),
Expand Down
2 changes: 1 addition & 1 deletion ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.2.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
log = "0.3"
log = "0.4"
libc = "0.2"
rand = "0.4"
ethkey = { path = "../ethkey" }
Expand Down
2 changes: 1 addition & 1 deletion hash-fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
futures = "0.1"
futures-cpupool = "0.1"
log = "0.3"
log = "0.4"
mime = "0.3"
mime_guess = "2.0.0-alpha.2"
rand = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion hw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "1.12.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
log = "0.3"
log = "0.4"
parking_lot = "0.6"
protobuf = "1.4"
hidapi = { git = "https://github.com/paritytech/hidapi-rs" }
Expand Down
2 changes: 1 addition & 1 deletion local-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ethcore = { path = "../ethcore" }
ethcore-io = { path = "../util/io" }
ethcore-transaction = { path = "../ethcore/transaction" }
kvdb = { git = "https://github.com/paritytech/parity-common" }
log = "0.3"
log = "0.4"
rlp = { git = "https://github.com/paritytech/parity-common" }
serde = "1.0"
serde_derive = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions logger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ license = "GPL-3.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
log = "0.3"
env_logger = "0.4"
log = "0.4"
env_logger = "0.5"
atty = "0.2"
lazy_static = "1.0"
regex = "0.2"
Expand Down
22 changes: 11 additions & 11 deletions logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod rotating;
use std::{env, thread, fs};
use std::sync::{Weak, Arc};
use std::io::Write;
use env_logger::LogBuilder;
use env_logger::{Builder as LogBuilder, Formatter};
use regex::Regex;
use ansi_term::Colour;
use parking_lot::Mutex;
Expand Down Expand Up @@ -68,12 +68,12 @@ pub fn setup_log(config: &Config) -> Result<Arc<RotatingLogger>, String> {
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::Error);
builder.filter(Some("ws"), LevelFilter::Warn);
builder.filter(Some("reqwest"), LevelFilter::Warn);
builder.filter(Some("hyper"), LevelFilter::Warn);
builder.filter(Some("rustls"), LevelFilter::Error);
// Enable info for others.
builder.filter(None, LogLevelFilter::Info);
builder.filter(None, LevelFilter::Info);

if let Ok(lvl) = env::var("RUST_LOG") {
levels.push_str(&lvl);
Expand All @@ -99,10 +99,10 @@ pub fn setup_log(config: &Config) -> Result<Arc<RotatingLogger>, String> {
None => None,
};

let format = move |record: &LogRecord| {
let format = move |buf: &mut Formatter, record: &Record| {
let timestamp = time::strftime("%Y-%m-%d %H:%M:%S %Z", &time::now()).unwrap();

let with_color = if max_log_level() <= LogLevelFilter::Info {
let with_color = if max_level() <= LevelFilter::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)));
Expand All @@ -122,16 +122,16 @@ pub fn setup_log(config: &Config) -> Result<Arc<RotatingLogger>, String> {
let _ = file.write_all(b"\n");
}
logger.append(removed_color);
if !isatty && record.level() <= LogLevel::Info && atty::is(atty::Stream::Stdout) {
if !isatty && record.level() <= Level::Info && atty::is(atty::Stream::Stdout) {
// duplicate INFO/WARN output to console
println!("{}", ret);
}

ret
write!(buf, "{}", ret)
};

builder.format(format);
builder.init()
builder.try_init()
.and_then(|_| {
*ROTATING_LOGGER.lock() = Arc::downgrade(&logs);
Ok(logs)
Expand Down
8 changes: 4 additions & 4 deletions logger/src/rotating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
//! Common log helper functions
use std::env;
use rlog::LogLevelFilter;
use env_logger::LogBuilder;
use rlog::LevelFilter;
use env_logger::Builder as 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);
builder.filter(None, LevelFilter::Info);

if let Ok(log) = env::var("RUST_LOG") {
builder.parse(&log);
}

if !builder.init().is_ok() {
if !builder.try_init().is_ok() {
println!("logger initialization failed!");
}
};
Expand Down
Loading

0 comments on commit e590874

Please sign in to comment.