diff --git a/src/bin/electrs.rs b/src/bin/electrs.rs index 5886c30..427f4b1 100644 --- a/src/bin/electrs.rs +++ b/src/bin/electrs.rs @@ -1,6 +1,5 @@ extern crate electrs; extern crate error_chain; -extern crate stderrlog; use error_chain::ChainedError; use std::time::Duration; @@ -48,17 +47,6 @@ fn run_server(config: &Config) -> Result<()> { fn main() { let config = Config::from_args(); - eprintln!("{:?}", config); - stderrlog::new() - .module(module_path!()) - .verbosity(config.verbosity) - .timestamp(if config.timestamp { - stderrlog::Timestamp::Microsecond - } else { - stderrlog::Timestamp::Off - }) - .init() - .expect("logging initialization failed"); if let Err(e) = run_server(&config) { eprintln!("server failed: {}", e.display_chain()); } diff --git a/src/config.rs b/src/config.rs index a7967e2..40ee472 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,12 @@ use clap::{App, Arg}; -use daemon::Network; use std::net::SocketAddr; +use stderrlog; + +use daemon::Network; #[derive(Debug)] pub struct Config { - pub verbosity: usize, - pub timestamp: bool, + pub log: stderrlog::StdErrLog, pub network_type: Network, // bitcoind JSONRPC endpoint pub db_path: String, // RocksDB directory path pub rpc_addr: SocketAddr, // for serving Electrum clients @@ -45,9 +46,16 @@ impl Config { true => Network::Testnet, }; let db_dir = m.value_of("db_dir").unwrap_or("./db"); + let mut log = stderrlog::new(); + log.verbosity(m.occurrences_of("verbosity") as usize); + log.timestamp(if m.is_present("timestamp") { + stderrlog::Timestamp::Microsecond + } else { + stderrlog::Timestamp::Off + }); + log.init().expect("logging initialization failed"); Config { - verbosity: m.occurrences_of("verbosity") as usize, - timestamp: m.is_present("timestamp"), + log, network_type, db_path: match network_type { Network::Mainnet => format!("{}/mainnet", db_dir), diff --git a/src/lib.rs b/src/lib.rs index cee920d..948387d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ extern crate hex; extern crate prometheus; extern crate rocksdb; extern crate serde; +extern crate stderrlog; extern crate time; extern crate tiny_http;