Add -v flag for log verbosity

This commit is contained in:
Roman Zeyde 2018-05-25 10:30:38 +03:00
parent fd03723842
commit 503946ee23
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -1,5 +1,6 @@
use argparse::{ArgumentParser, StoreTrue};
use bitcoin::util::hash::Sha256dHash;
use simplelog::LevelFilter;
use std::fs::OpenOptions;
use std::net::SocketAddr;
use std::sync::Arc;
@ -12,6 +13,7 @@ use {daemon, index, query, rpc, store};
#[derive(Debug)]
struct Config {
log_file: String,
log_level: LevelFilter,
network_type: Network, // bitcoind JSONRPC endpoint
db_path: &'static str, // RocksDB directory path
rpc_addr: SocketAddr, // for serving Electrum clients
@ -20,6 +22,7 @@ struct Config {
impl Config {
pub fn from_args() -> Config {
let mut testnet = false;
let mut verbose = false;
{
let mut parser = ArgumentParser::new();
parser.set_description("Bitcoin indexing server.");
@ -28,6 +31,11 @@ impl Config {
StoreTrue,
"Connect to a testnet bitcoind instance",
);
parser.refer(&mut verbose).add_option(
&["-v", "--verbose"],
StoreTrue,
"More verbose logging to stderr",
);
parser.parse_args_or_exit();
}
let network_type = match testnet {
@ -36,6 +44,11 @@ impl Config {
};
Config {
log_file: "indexrs.log".to_string(),
log_level: if verbose {
LevelFilter::Debug
} else {
LevelFilter::Info
},
network_type: network_type,
db_path: match network_type {
Network::Mainnet => "./db/mainnet",
@ -111,7 +124,7 @@ fn setup_logging(config: &Config) {
let mut cfg = Config::default();
cfg.time_format = Some("%F %H:%M:%S%.3f");
CombinedLogger::init(vec![
TermLogger::new(LevelFilter::Info, cfg.clone()).unwrap(),
TermLogger::new(config.log_level, cfg.clone()).unwrap(),
WriteLogger::new(
LevelFilter::Debug,
cfg.clone(),