Merge pull request #263 from ethcore/log

Common log init function
This commit is contained in:
Gav Wood 2016-01-29 16:21:38 +01:00
commit 1b5845791f
3 changed files with 31 additions and 22 deletions

View File

@ -1,6 +1,3 @@
use std::env;
use log::{LogLevelFilter};
use env_logger::LogBuilder;
use super::test_common::*; use super::test_common::*;
use client::{BlockChainClient,Client}; use client::{BlockChainClient,Client};
use pod_state::*; use pod_state::*;
@ -13,24 +10,8 @@ pub enum ChainEra {
Homestead, 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> { 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 json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new(); let mut failed = Vec::new();

View File

@ -43,8 +43,6 @@ extern crate tiny_keccak;
#[macro_use] #[macro_use]
extern crate heapsize; extern crate heapsize;
#[macro_use] #[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate itertools; extern crate itertools;
@ -56,6 +54,8 @@ extern crate arrayvec;
extern crate elastic_array; extern crate elastic_array;
extern crate crossbeam; extern crate crossbeam;
extern crate serde; extern crate serde;
#[macro_use]
extern crate log as rlog;
/// TODO [Gav Wood] Please document me /// TODO [Gav Wood] Please document me
pub mod standard; pub mod standard;
@ -98,6 +98,7 @@ pub mod semantic_version;
pub mod io; pub mod io;
/// TODO [Gav Wood] Please document me /// TODO [Gav Wood] Please document me
pub mod network; pub mod network;
pub mod log;
pub use common::*; pub use common::*;
pub use misc::*; pub use misc::*;
@ -118,3 +119,4 @@ pub use squeeze::*;
pub use semantic_version::*; pub use semantic_version::*;
pub use network::*; pub use network::*;
pub use io::*; pub use io::*;
pub use log::*;

26
util/src/log.rs Normal file
View File

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