Skip to content

Commit be6a6d8

Browse files
committed
refactor(logging): make info the default log level, demote noisy messages to debug
Base verbosity is now info (error+warn+info) without any flags. Each -v flag adds one level: -v=debug, -vv=trace. This replaces the previous approach of temporarily overriding the log level during startup and reverting after. Info-level messages are now always visible by default, eliminating the set/revert mechanism. Noisy messages demoted to debug: per-request HTTP logging, peer connect/disconnect, mempool stats, header download progress, and discovery server list dumps. Promoted 'opening DB' to info for startup visibility.
1 parent 6a41f92 commit be6a6d8

File tree

11 files changed

+16
-35
lines changed

11 files changed

+16
-35
lines changed

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ fn run_server(config: Arc<Config>, salt_rwlock: Arc<RwLock<String>>) -> Result<(
137137
Arc::clone(&salt_rwlock),
138138
);
139139

140-
info!("startup complete, switching to configured log verbosity");
141-
log::set_max_level(config.log_level_filter());
140+
info!("startup complete");
142141

143142
let main_loop_count = metrics.gauge(MetricOpts::new(
144143
"electrs_main_loop_count",

src/config.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ pub struct Config {
4343
pub rpc_logging: RpcLogging,
4444
pub zmq_addr: Option<SocketAddr>,
4545

46-
/// The user's requested log verbosity level (number of -v flags).
47-
/// Used to restore log level after startup logging completes.
48-
pub log_verbosity: usize,
49-
5046
/// RocksDB block cache size in MB (per database)
5147
/// Caches decompressed data blocks, plus index and filter blocks (via cache_index_and_filter_blocks).
5248
/// Total memory usage = cache_size * 3_databases (txstore, history, cache)
@@ -113,7 +109,7 @@ impl Config {
113109
Arg::with_name("verbosity")
114110
.short("v")
115111
.multiple(true)
116-
.help("Increase logging verbosity"),
112+
.help("Increase logging verbosity (default: info, -v: debug, -vv: trace)"),
117113
)
118114
.arg(
119115
Arg::with_name("timestamp")
@@ -467,13 +463,10 @@ impl Config {
467463
.value_of("electrum_public_hosts")
468464
.map(|s| serde_json::from_str(s).expect("invalid --electrum-public-hosts"));
469465

470-
let user_verbosity = m.occurrences_of("verbosity") as usize;
471-
// Initialize logging at info level (verbosity 2) minimum so that
472-
// startup milestone logs are always visible. After startup completes,
473-
// the log level is dropped to the user's configured verbosity.
474-
let startup_verbosity = std::cmp::max(user_verbosity, 2);
475466
let mut log = stderrlog::new();
476-
log.verbosity(startup_verbosity);
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);
477470
log.timestamp(if m.is_present("timestamp") {
478471
stderrlog::Timestamp::Millisecond
479472
} else {
@@ -518,7 +511,6 @@ impl Config {
518511
initial_sync_batch_size: value_t_or_exit!(m, "initial_sync_batch_size", usize),
519512
db_cache_index_filter_blocks: m.is_present("cache_index_filter_blocks"),
520513
zmq_addr,
521-
log_verbosity: user_verbosity,
522514

523515
#[cfg(feature = "liquid")]
524516
parent_network,
@@ -536,16 +528,6 @@ impl Config {
536528
config
537529
}
538530

539-
pub fn log_level_filter(&self) -> log::LevelFilter {
540-
match self.log_verbosity {
541-
0 => log::LevelFilter::Error,
542-
1 => log::LevelFilter::Warn,
543-
2 => log::LevelFilter::Info,
544-
3 => log::LevelFilter::Debug,
545-
_ => log::LevelFilter::Trace,
546-
}
547-
}
548-
549531
pub fn cookie_getter(&self) -> Arc<dyn CookieGetter> {
550532
if let Some(ref value) = self.cookie {
551533
Arc::new(StaticCookie {

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) -> 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/mempool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl Mempool {
559559
.difference(&indexed_txids)
560560
.collect::<Vec<_>>();
561561

562-
info!(
562+
debug!(
563563
"mempool with total {} txs, {} indexed locally, {} to fetch",
564564
bitcoind_txids.len(),
565565
indexed_txids.len(),

0 commit comments

Comments
 (0)