From 5ce7a93370b5a0795344a8a1c5aabe084ca4229d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 12 May 2020 10:42:42 +0200 Subject: [PATCH 1/2] Allow passing multiple --log CLI options --- client/cli/src/commands/mod.rs | 2 +- client/cli/src/config.rs | 11 +++++++---- client/cli/src/params/shared_params.rs | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index d2bab5bca0760..54a6f9b743221 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -396,7 +396,7 @@ macro_rules! substrate_cli_subcommands { } } - fn log_filters(&self) -> $crate::Result<::std::option::Option> { + fn log_filters(&self) -> $crate::Result { match self { $($enum::$variant(cmd) => cmd.log_filters()),* } diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index f2a6715cf2f56..6b70e2c69b998 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -472,9 +472,12 @@ pub trait CliConfiguration: Sized { /// Get the filters for the logging. /// + /// This should be a list of comma-separated values. + /// Example: `foo=trace,bar=debug,bar=info` + /// /// By default this is retrieved from `SharedParams`. - fn log_filters(&self) -> Result> { - Ok(self.shared_params().log_filters()) + fn log_filters(&self) -> Result { + Ok(self.shared_params().log_filters().join(",")) } /// Initialize substrate. This must be done only once. @@ -485,12 +488,12 @@ pub trait CliConfiguration: Sized { /// 2. Raise the FD limit /// 3. Initialize the logger fn init(&self) -> Result<()> { - let logger_pattern = self.log_filters()?.unwrap_or_default(); + let logger_pattern = self.log_filters()?; sp_panic_handler::set(C::support_url(), C::impl_version()); fdlimit::raise_fd_limit(); - init_logger(logger_pattern.as_str()); + init_logger(&logger_pattern); Ok(()) } diff --git a/client/cli/src/params/shared_params.rs b/client/cli/src/params/shared_params.rs index 68c9a30453528..c8381cd069bb9 100644 --- a/client/cli/src/params/shared_params.rs +++ b/client/cli/src/params/shared_params.rs @@ -42,7 +42,7 @@ pub struct SharedParams { /// Log levels (least to most verbose) are error, warn, info, debug, and trace. /// By default, all targets log `info`. The global log level can be set with -l. #[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")] - pub log: Option, + pub log: Vec, } impl SharedParams { @@ -71,7 +71,7 @@ impl SharedParams { } /// Get the filters for the logging - pub fn log_filters(&self) -> Option { - self.log.clone() + pub fn log_filters(&self) -> &[String] { + &self.log } } From 95f44f99f64e718a33afc3f08946eae266ce6eaf Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 12 May 2020 10:47:34 +0200 Subject: [PATCH 2/2] Comment typo --- client/cli/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index 6b70e2c69b998..56830f2076328 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -473,7 +473,7 @@ pub trait CliConfiguration: Sized { /// Get the filters for the logging. /// /// This should be a list of comma-separated values. - /// Example: `foo=trace,bar=debug,bar=info` + /// Example: `foo=trace,bar=debug,baz=info` /// /// By default this is retrieved from `SharedParams`. fn log_filters(&self) -> Result {