1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-24 15:02:21 +01:00

Allow setting logging filters via configuration

Similar to `RUST_LOG` environment variable.
This commit is contained in:
Roman Zeyde 2021-11-08 15:03:06 +02:00
parent aa789e7575
commit cbdca8c266
2 changed files with 14 additions and 5 deletions

View file

@ -125,3 +125,8 @@ name = "server_banner"
type = "String" type = "String"
doc = "The banner to be shown in the Electrum console" doc = "The banner to be shown in the Electrum console"
default = "concat!(\"Welcome to electrs \", env!(\"CARGO_PKG_VERSION\"), \" (Electrum Rust Server)!\").to_owned()" default = "concat!(\"Welcome to electrs \", env!(\"CARGO_PKG_VERSION\"), \" (Electrum Rust Server)!\").to_owned()"
[[param]]
name = "log_filters"
type = "String"
doc = "Logging filters, overriding `RUST_LOG` environment variable (see https://docs.rs/env_logger/ for details)"

View file

@ -288,9 +288,10 @@ impl Config {
}); });
if config.verbose > 0 { if config.verbose > 0 {
eprintln!("Error: please use `log_filter` to set logging verbosity",); eprintln!("Error: please use `log_filters` to set logging verbosity",);
std::process::exit(1); std::process::exit(1);
} }
let log_filters = config.log_filters;
let index_lookup_limit = match config.index_lookup_limit { let index_lookup_limit = match config.index_lookup_limit {
0 => None, 0 => None,
@ -335,10 +336,13 @@ impl Config {
"Starting electrs {} on {} {} with {:?}", "Starting electrs {} on {} {} with {:?}",
ELECTRS_VERSION, ARCH, OS, config ELECTRS_VERSION, ARCH, OS, config
); );
env_logger::Builder::from_default_env() let mut builder = env_logger::Builder::from_default_env();
.default_format() builder.default_format().format_timestamp_millis();
.format_timestamp_millis() if let Some(log_filters) = &log_filters {
.init(); builder.parse_filters(log_filters);
}
builder.init();
config config
} }
} }