diff --git a/core/cli/src/lib.rs b/core/cli/src/lib.rs index 78a76fc1bc406..fc11f873af47b 100644 --- a/core/cli/src/lib.rs +++ b/core/cli/src/lib.rs @@ -187,12 +187,13 @@ fn is_node_name_valid(_name: &str) -> Result<(), &str> { /// `RP` is are custom parameters for the run command. This needs to be a `struct`! The custom /// parameters are visible to the user as if they were normal run command parameters. If no custom /// parameters are required, `NoCustom` can be used as type here. -pub fn parse_and_execute<'a, F, CC, RP, S, RS, E, I, T>( +pub fn parse_and_execute<'a, F, CC, RP, S, RS, E, I, T, L>( spec_factory: S, version: &VersionInfo, impl_name: &'static str, args: I, exit: E, + init_logger_f: L, run_service: RS, ) -> error::Result> where @@ -201,6 +202,7 @@ where CC: StructOpt + Clone + GetLogFilter, RP: StructOpt + Clone + AugmentClap, E: IntoExit, + L: FnOnce(&str, MergeParameters) -> Result<(), String>, RS: FnOnce(E, RunCmd, RP, FactoryFullConfiguration) -> Result<(), String>, I: IntoIterator, T: Into + Clone, @@ -223,7 +225,12 @@ where .get_matches_from(args); let cli_args = CoreParams::::from_clap(&matches); - init_logger(cli_args.get_log_filter().as_ref().map(|v| v.as_ref()).unwrap_or("")); + let pattern = cli_args.get_log_filter().clone().unwrap_or("".to_string()); + match cli_args.clone() { + params::CoreParams::Run(params) => init_logger_f(&pattern, params)?, + _ => init_logger(&pattern), + } + fdlimit::raise_fd_limit(); match cli_args { @@ -779,7 +786,7 @@ fn network_path(base_path: &Path, chain_id: &str) -> PathBuf { path } -fn init_logger(pattern: &str) { +pub fn init_logger(pattern: &str) { use ansi_term::Colour; let mut builder = env_logger::Builder::new(); @@ -837,7 +844,7 @@ fn init_logger(pattern: &str) { builder.init(); } -fn kill_color(s: &str) -> String { +pub fn kill_color(s: &str) -> String { lazy_static! { static ref RE: Regex = Regex::new("\x1b\\[[^m]+m").expect("Error initializing color regex"); } diff --git a/node-template/src/cli.rs b/node-template/src/cli.rs index f41674631e8a4..03aa1d0d04207 100644 --- a/node-template/src/cli.rs +++ b/node-template/src/cli.rs @@ -3,7 +3,7 @@ use futures::{future, Future, sync::oneshot}; use std::cell::RefCell; use tokio::runtime::Runtime; pub use substrate_cli::{VersionInfo, IntoExit, error}; -use substrate_cli::{informant, parse_and_execute, NoCustom}; +use substrate_cli::{informant, parse_and_execute, init_logger, NoCustom}; use substrate_service::{ServiceFactory, Roles as ServiceRoles}; use crate::chain_spec; use std::ops::Deref; @@ -15,8 +15,12 @@ pub fn run(args: I, exit: E, version: VersionInfo) -> error::Result<()> T: Into + Clone, E: IntoExit, { - parse_and_execute::( + parse_and_execute::( load_spec, &version, "substrate-node", args, exit, + |s, _| { + init_logger(s); + Ok(()) + }, |exit, _cli_args, _custom_args, config| { info!("{}", version.name); info!(" version {}", config.full_version()); diff --git a/node/cli/src/lib.rs b/node/cli/src/lib.rs index 6530a1d7be7aa..39973d2b10522 100644 --- a/node/cli/src/lib.rs +++ b/node/cli/src/lib.rs @@ -79,8 +79,12 @@ pub fn run(args: I, exit: E, version: cli::VersionInfo) -> error::Resul T: Into + Clone, E: IntoExit, { - cli::parse_and_execute::( + cli::parse_and_execute::( load_spec, &version, "substrate-node", args, exit, + |s, _| { + cli::init_logger(s); + Ok(()) + }, |exit, _cli_args, _custom_args, config| { info!("{}", version.name); info!(" version {}", config.full_version());