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

Commit

Permalink
Merge pull request #263 from ethcore/log
Browse files Browse the repository at this point in the history
Common log init function
  • Loading branch information
Gav Wood committed Jan 29, 2016
2 parents 45bc887 + 233684b commit 1b58457
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
21 changes: 1 addition & 20 deletions src/tests/chain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::env;
use log::{LogLevelFilter};
use env_logger::LogBuilder;
use super::test_common::*;
use client::{BlockChainClient,Client};
use pod_state::*;
Expand All @@ -13,24 +10,8 @@ pub enum ChainEra {
Homestead,
}

lazy_static! {
static ref LOG_DUMMY: bool = {
let mut builder = LogBuilder::new();
builder.filter(None, LogLevelFilter::Info);

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

if let Ok(_) = builder.init() {
println!("logger initialized");
}
true
};
}

pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
let _ = LOG_DUMMY.deref();
init_log();
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new();

Expand Down
6 changes: 4 additions & 2 deletions util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ extern crate tiny_keccak;
#[macro_use]
extern crate heapsize;
#[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate itertools;
Expand All @@ -56,6 +54,8 @@ extern crate arrayvec;
extern crate elastic_array;
extern crate crossbeam;
extern crate serde;
#[macro_use]
extern crate log as rlog;

/// TODO [Gav Wood] Please document me
pub mod standard;
Expand Down Expand Up @@ -98,6 +98,7 @@ pub mod semantic_version;
pub mod io;
/// TODO [Gav Wood] Please document me
pub mod network;
pub mod log;

pub use common::*;
pub use misc::*;
Expand All @@ -118,3 +119,4 @@ pub use squeeze::*;
pub use semantic_version::*;
pub use network::*;
pub use io::*;
pub use log::*;
26 changes: 26 additions & 0 deletions util/src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Common log helper functions
use std::env;
use rlog::{LogLevelFilter};
use env_logger::LogBuilder;

lazy_static! {
static ref LOG_DUMMY: bool = {
let mut builder = LogBuilder::new();
builder.filter(None, LogLevelFilter::Info);

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

if let Ok(_) = builder.init() {
println!("logger initialized");
}
true
};
}

/// Intialize log with default settings
pub fn init_log() {
let _ = *LOG_DUMMY;
}

0 comments on commit 1b58457

Please sign in to comment.