From cd86c583c92668426c35cc174401155bf2880c1f Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 29 May 2020 12:51:34 +0200 Subject: [PATCH] Change OutputFormat enum to struct --- client/cli/src/runner.rs | 3 ++- client/informant/src/display.rs | 15 ++++++++------- client/informant/src/lib.rs | 28 +++++++++++++--------------- utils/browser/src/lib.rs | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 9587606c45fc1..fa45e9a8b30ef 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -212,7 +212,8 @@ impl Runner { let prefix = self.config.informant_prefix.clone(); let service = service_builder(self.config)?; - let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured { + let informant_future = sc_informant::build(&service, sc_informant::OutputFormat { + colors: true, prefix, }); let _informant_handle = self.tokio_runtime.spawn(informant_future); diff --git a/client/informant/src/display.rs b/client/informant/src/display.rs index 4a20af281487b..afa45620a3507 100644 --- a/client/informant/src/display.rs +++ b/client/informant/src/display.rs @@ -73,12 +73,12 @@ impl InformantDisplay { (SyncState::Downloading, Some(n)) => ("⚙️ ", format!("Syncing{}", speed), format!(", target=#{}", n)), }; - match &self.format { - OutputFormat::Coloured { prefix } => info!( + if self.format.colors { + info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, - prefix, + self.format.prefix, Colour::White.bold().paint(&status), target, Colour::White.bold().paint(format!("{}", num_connected_peers)), @@ -88,12 +88,13 @@ impl InformantDisplay { info.chain.finalized_hash, Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))), Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))), - ), - OutputFormat::Plain { prefix } => info!( + ) + } else { + info!( target: "substrate", "{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", level, - prefix, + self.format.prefix, status, target, num_connected_peers, @@ -103,7 +104,7 @@ impl InformantDisplay { info.chain.finalized_hash, TransferRateFormat(net_status.average_download_per_sec), TransferRateFormat(net_status.average_upload_per_sec), - ), + ) } } } diff --git a/client/informant/src/lib.rs b/client/informant/src/lib.rs index 65942ebf5ee3f..460a437881edd 100644 --- a/client/informant/src/lib.rs +++ b/client/informant/src/lib.rs @@ -30,13 +30,9 @@ mod display; /// The format to print telemetry output in. #[derive(Clone)] -pub enum OutputFormat { - Coloured { - prefix: String, - }, - Plain { - prefix: String, - }, +pub struct OutputFormat { + pub prefix: String, + pub colors: bool, } /// Creates an informant in the form of a `Future` that must be polled regularly. @@ -101,16 +97,18 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur last_best = Some((n.header.number().clone(), n.hash.clone())); } - match &format { - OutputFormat::Coloured { prefix } => info!( + if format.colors { + info!( target: "substrate", "✨ {}Imported #{} ({})", - prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, - ), - OutputFormat::Plain { prefix } => info!( - target: "substrate", "✨ {}Imported #{} ({})", - prefix, n.header.number(), n.hash, - ), + format.prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash, + ) + } else { + info!( + target: "substrate", + "✨ {}Imported #{} ({})", + format.prefix, n.header.number(), n.hash, + ) } future::ready(()) diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs index 2293501d06ee0..7f7fc1f8a2999 100644 --- a/utils/browser/src/lib.rs +++ b/utils/browser/src/lib.rs @@ -121,7 +121,7 @@ pub fn start_client(mut service: impl AbstractService) -> Client { wasm_bindgen_futures::spawn_local( sc_informant::build( &service, - sc_informant::OutputFormat::Plain { prefix: Default::default() }, + sc_informant::OutputFormat { colors: false, prefix: Default::default() }, ).map(drop) );