Browse Source

Allow timestamping log entries

refactor-mempool
Roman Zeyde 6 years ago
parent
commit
4cc417232d
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 5
      src/bin/electrs.rs
  2. 7
      src/config.rs

5
src/bin/electrs.rs

@ -52,6 +52,11 @@ fn main() {
stderrlog::new() stderrlog::new()
.module(module_path!()) .module(module_path!())
.verbosity(config.verbosity) .verbosity(config.verbosity)
.timestamp(if config.timestamp {
stderrlog::Timestamp::Microsecond
} else {
stderrlog::Timestamp::Off
})
.init() .init()
.expect("logging initialization failed"); .expect("logging initialization failed");
if let Err(e) = run_server(&config) { if let Err(e) = run_server(&config) {

7
src/config.rs

@ -5,6 +5,7 @@ use std::net::SocketAddr;
#[derive(Debug)] #[derive(Debug)]
pub struct Config { pub struct Config {
pub verbosity: usize, pub verbosity: usize,
pub timestamp: bool,
pub network_type: Network, // bitcoind JSONRPC endpoint pub network_type: Network, // bitcoind JSONRPC endpoint
pub db_path: String, // RocksDB directory path pub db_path: String, // RocksDB directory path
pub rpc_addr: SocketAddr, // for serving Electrum clients pub rpc_addr: SocketAddr, // for serving Electrum clients
@ -21,6 +22,11 @@ impl Config {
.multiple(true) .multiple(true)
.help("Increase logging verbosity"), .help("Increase logging verbosity"),
) )
.arg(
Arg::with_name("timestamp")
.long("timestamp")
.help("Prepend log lines with a timestamp"),
)
.arg( .arg(
Arg::with_name("db_dir") Arg::with_name("db_dir")
.short("d") .short("d")
@ -41,6 +47,7 @@ impl Config {
let db_dir = m.value_of("db_dir").unwrap_or("./db"); let db_dir = m.value_of("db_dir").unwrap_or("./db");
Config { Config {
verbosity: m.occurrences_of("verbosity") as usize, verbosity: m.occurrences_of("verbosity") as usize,
timestamp: m.is_present("timestamp"),
network_type, network_type,
db_path: match network_type { db_path: match network_type {
Network::Mainnet => format!("{}/mainnet", db_dir), Network::Mainnet => format!("{}/mainnet", db_dir),

Loading…
Cancel
Save