Skip to content

Commit 3db3dca

Browse files
committed
feat(logging): default to info-level logging
Electrs has been observed starting, running for a few minutes, then dying silently in environments with no verbosity flags set. With the previous default (error-only), there was zero diagnostic output. Base verbosity is now info (error+warn+info) without any flags. Each -v flag adds one level: -v=debug, -vv=trace. Adds explicit info! milestone logs at each startup phase in src/bin/electrs.rs: daemon connection, DB open, initial sync start/complete, mempool load, startup complete. Promotes messages in schema.rs (block/header counts, tip) and db.rs (opening DB) to info so they fire on startup. Demotes noisy messages to debug: per-request HTTP logging, peer connect/disconnect, header download progress, and the discovery server-list dump. Drops the now-unnecessary -vvvv flag from README, doc/usage.md, and contrib/electrs.service.
1 parent 69fcfc5 commit 3db3dca

11 files changed

Lines changed: 26 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Install Rust, Bitcoin Core (no `txindex` needed) and the `clang` and `cmake` pac
1515
```bash
1616
$ git clone https://github.com/blockstream/electrs && cd electrs
1717
$ git checkout new-index
18-
$ cargo run --release --bin electrs -- -vvvv --daemon-dir ~/.bitcoin
18+
$ cargo run --release --bin electrs -- --daemon-dir ~/.bitcoin
1919

2020
# Or for liquid:
21-
$ cargo run --features liquid --release --bin electrs -- -vvvv --network liquid --daemon-dir ~/.liquid
21+
$ cargo run --features liquid --release --bin electrs -- --network liquid --daemon-dir ~/.liquid
2222
```
2323

2424
See [electrs's original documentation](https://github.com/romanz/electrs/blob/master/doc/usage.md) for more detailed instructions.

contrib/electrs.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Description=Electrum Rust Server
33

44
[Service]
55
Type=simple
6-
ExecStart=/path/to/electrs/target/release/electrs -vvvv --db-dir /path/to/electrs/db/
6+
ExecStart=/path/to/electrs/target/release/electrs --db-dir /path/to/electrs/db/
77
Restart=on-failure
88
RestartSec=60
99
Environment="RUST_BACKTRACE=1"

doc/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Otherwise, [`~/.bitcoin/.cookie`](https://github.com/bitcoin/bitcoin/blob/021218
3232

3333
First index sync should take ~1.5 hours:
3434
```bash
35-
$ cargo run --release -- -vvv --timestamp --db-dir ./db [--cookie="USER:PASSWORD"]
35+
$ cargo run --release -- --timestamp --db-dir ./db [--cookie="USER:PASSWORD"]
3636
2018-08-17T18:27:42 - INFO - NetworkInfo { version: 179900, subversion: "/Satoshi:0.17.99/" }
3737
2018-08-17T18:27:42 - INFO - BlockchainInfo { chain: "main", blocks: 537204, headers: 537204, bestblockhash: "0000000000000000002956768ca9421a8ddf4e53b1d81e429bd0125a383e3636", pruned: false, initialblockdownload: false }
3838
2018-08-17T18:27:42 - DEBUG - opening DB at "./db/mainnet"

src/bin/electrs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ fn run_server(config: Arc<Config>, salt_rwlock: Arc<RwLock<String>>) -> Result<(
5757
let metrics = Metrics::new(config.monitoring_addr);
5858
metrics.start();
5959

60+
info!("starting electrs");
61+
6062
if let Some(zmq_addr) = config.zmq_addr.as_ref() {
6163
zmq::start(&format!("tcp://{zmq_addr}"), block_hash_notify);
6264
}
6365

66+
info!("connecting to daemon at {}", config.daemon_rpc_addr);
6467
let daemon = Arc::new(Daemon::new(
6568
&config.daemon_dir,
6669
&config.blocks_dir,
@@ -71,14 +74,17 @@ fn run_server(config: Arc<Config>, salt_rwlock: Arc<RwLock<String>>) -> Result<(
7174
signal.clone(),
7275
&metrics,
7376
)?);
77+
info!("opening database at {}", config.db_path.display());
7478
let store = Arc::new(Store::open(&config, &metrics, true));
7579
let mut indexer = Indexer::open(
7680
Arc::clone(&store),
7781
fetch_from(&config, &store),
7882
&config,
7983
&metrics,
8084
);
85+
info!("starting initial sync");
8186
let mut tip = indexer.update(&daemon)?;
87+
info!("initial sync complete, tip at {}", tip);
8288

8389
let chain = Arc::new(ChainQuery::new(
8490
Arc::clone(&store),
@@ -93,6 +99,7 @@ fn run_server(config: Arc<Config>, salt_rwlock: Arc<RwLock<String>>) -> Result<(
9399
precache::precache(&chain, precache_scripthashes);
94100
}
95101

102+
info!("loading mempool");
96103
let mempool = Arc::new(RwLock::new(Mempool::new(
97104
Arc::clone(&chain),
98105
&metrics,
@@ -130,6 +137,8 @@ fn run_server(config: Arc<Config>, salt_rwlock: Arc<RwLock<String>>) -> Result<(
130137
Arc::clone(&salt_rwlock),
131138
);
132139

140+
info!("startup complete");
141+
133142
let main_loop_count = metrics.gauge(MetricOpts::new(
134143
"electrs_main_loop_count",
135144
"count of iterations of electrs main loop each 5 seconds or after interrupts",

src/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Config {
109109
Arg::with_name("verbosity")
110110
.short("v")
111111
.multiple(true)
112-
.help("Increase logging verbosity"),
112+
.help("Increase logging verbosity (default: info, -v: debug, -vv: trace)"),
113113
)
114114
.arg(
115115
Arg::with_name("timestamp")
@@ -464,7 +464,9 @@ impl Config {
464464
.map(|s| serde_json::from_str(s).expect("invalid --electrum-public-hosts"));
465465

466466
let mut log = stderrlog::new();
467-
log.verbosity(m.occurrences_of("verbosity") as usize);
467+
// Base verbosity is 2 (Info), each -v flag adds one level:
468+
// no flags = Info, -v = Debug, -vv = Trace
469+
log.verbosity(2 + m.occurrences_of("verbosity") as usize);
468470
log.timestamp(if m.is_present("timestamp") {
469471
stderrlog::Timestamp::Millisecond
470472
} else {

src/daemon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ impl Daemon {
789789

790790
result.append(&mut headers);
791791

792-
info!(
792+
debug!(
793793
"downloaded {}/{} block headers ({:.0}%)",
794794
result.len(),
795795
tip_height + 1,

src/electrum/discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ mod tests {
588588

589589
debug!("{:#?}", discovery);
590590

591-
info!("{}", json!(discovery.get_servers()));
591+
debug!("{}", json!(discovery.get_servers()));
592592

593593
Ok(())
594594
}

src/electrum/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ impl RPC {
870870
let salt = salt_rwlock.read().unwrap().clone();
871871

872872
let spawned = spawn_thread("peer", move || {
873-
info!("[{}] connected peer", addr);
873+
debug!("[{}] connected peer", addr);
874874
let conn = Connection::new(
875875
query,
876876
stream,
@@ -884,7 +884,7 @@ impl RPC {
884884
salt,
885885
);
886886
conn.run(receiver);
887-
info!("[{}] disconnected peer", addr);
887+
debug!("[{}] disconnected peer", addr);
888888
let _ = garbage_sender.send(std::thread::current().id());
889889
});
890890

src/new_index/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum DBFlush {
9191

9292
impl DB {
9393
pub fn open(path: &Path, config: &Config, verify_compat: bool, shared_cache: &rocksdb::Cache) -> DB {
94-
debug!("opening DB at {:?}", path);
94+
info!("opening DB at {:?}", path);
9595
let mut db_opts = rocksdb::Options::default();
9696
db_opts.create_if_missing(true);
9797
db_opts.set_max_open_files(100_000); // TODO: make sure to `ulimit -n` this process correctly

src/new_index/schema.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ impl Store {
7272

7373
let txstore_db = DB::open(&path.join("txstore"), config, verify_compat, &shared_cache);
7474
let added_blockhashes = load_blockhashes(&txstore_db, &BlockRow::done_filter());
75-
debug!("{} blocks were added", added_blockhashes.len());
75+
info!("{} blocks were added", added_blockhashes.len());
7676

7777
let history_db = DB::open(&path.join("history"), config, verify_compat, &shared_cache);
7878
let indexed_blockhashes = load_blockhashes(&history_db, &BlockRow::done_filter());
79-
debug!("{} blocks were indexed", indexed_blockhashes.len());
79+
info!("{} blocks were indexed", indexed_blockhashes.len());
8080

8181
let cache_db = DB::open(&path.join("cache"), config, verify_compat, &shared_cache);
8282

@@ -101,7 +101,7 @@ impl Store {
101101
.expect("invalid header chain")
102102
.prev_blockhash;
103103
}
104-
debug!(
104+
info!(
105105
"{} headers were loaded, tip at {:?}",
106106
headers_map.len(),
107107
tip_hash

0 commit comments

Comments
 (0)