Skip to content

Commit

Permalink
Change OutputFormat enum to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed May 29, 2020
1 parent d3c1d52 commit cd86c58
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
3 changes: 2 additions & 1 deletion client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ impl<C: SubstrateCli> Runner<C> {
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);
Expand Down
15 changes: 8 additions & 7 deletions client/informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ impl<B: BlockT> InformantDisplay<B> {
(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)),
Expand All @@ -88,12 +88,13 @@ impl<B: BlockT> InformantDisplay<B> {
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,
Expand All @@ -103,7 +104,7 @@ impl<B: BlockT> InformantDisplay<B> {
info.chain.finalized_hash,
TransferRateFormat(net_status.average_download_per_sec),
TransferRateFormat(net_status.average_upload_per_sec),
),
)
}
}
}
Expand Down
28 changes: 13 additions & 15 deletions client/informant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion utils/browser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down

0 comments on commit cd86c58

Please sign in to comment.