Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
client: fix log filters (#7241)
* client: fix multiple logger filters

* client: add test for log filters setup
  • Loading branch information
andresilva authored and jordy25519 committed Nov 10, 2020
commit 273005f578e476c7ea3331e029ecf63e49f71960
13 changes: 10 additions & 3 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use structopt::{
clap::{self, AppSettings},
StructOpt,
};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::{filter::Directive, layer::SubscriberExt};

/// Substrate client CLI
///
Expand Down Expand Up @@ -234,6 +234,13 @@ pub fn init_logger(
tracing_receiver: sc_tracing::TracingReceiver,
tracing_targets: Option<String>,
) -> std::result::Result<(), String> {
fn parse_directives(dirs: impl AsRef<str>) -> Vec<Directive> {
dirs.as_ref()
.split(',')
.filter_map(|s| s.parse().ok())
.collect()
}

if let Err(e) = tracing_log::LogTracer::init() {
return Err(format!(
"Registering Substrate logger failed: {:}!", e
Expand All @@ -257,7 +264,7 @@ pub fn init_logger(
if lvl != "" {
// We're not sure if log or tracing is available at this moment, so silently ignore the
// parse error.
if let Ok(directive) = lvl.parse() {
for directive in parse_directives(lvl) {
env_filter = env_filter.add_directive(directive);
}
}
Expand All @@ -266,7 +273,7 @@ pub fn init_logger(
if pattern != "" {
// We're not sure if log or tracing is available at this moment, so silently ignore the
// parse error.
if let Ok(directive) = pattern.parse() {
for directive in parse_directives(pattern) {
env_filter = env_filter.add_directive(directive);
}
}
Expand Down