mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Allow adding a prefix to the informant (#6174)
* Initial commit Forked at:1d93746b64Parent branch: origin/master * Add a Service Configuration's field + adapt informant + provide means to CLI * CLEANUP Forked at:1d93746b64Parent branch: origin/master * fix tests * fixed bad path to object * Change OutputFormat enum to struct * Add informant_prefix to builder and service * Revert "Change OutputFormat enum to struct" This reverts commit cd86c583c92668426c35cc174401155bf2880c1f. * Revert "fix tests" This reverts commit a3c306ebe94720f350c5bc74b9c5fcde2565d340. * Revert "Add a Service Configuration's field + adapt informant + provide means to CLI" This reverts commit 9c2e7267423305705916c30d605893524113c8e3. * Implementation using the ServiceBuilder * reduce line length * fix line width again * WIP Forked at:1d93746b64Parent branch: origin/master * WIP Forked at:1d93746b64Parent branch: origin/master * WIP Forked at:1d93746b64Parent branch: origin/master * use struct instead of enum * WIP Forked at:1d93746b64Parent branch: origin/master * Update client/service/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * improve doc * Update client/service/src/builder.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/builder.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * change code * Update client/informant/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * enable_color * reorg log * remove macro * Removed builder for informant prefix * fix doc * Update client/informant/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/informant/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/informant/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/informant/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/builder.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/builder.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/builder.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -19,33 +19,66 @@
|
||||
//! Console informant. Prints sync progress and block events. Runs on the calling thread.
|
||||
|
||||
use ansi_term::Colour;
|
||||
use sc_client_api::{BlockchainEvents, UsageProvider};
|
||||
use futures::prelude::*;
|
||||
use log::{info, warn, trace};
|
||||
use sp_runtime::traits::Header;
|
||||
use sc_service::AbstractService;
|
||||
use log::{info, trace, warn};
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use sc_client_api::{BlockchainEvents, UsageProvider};
|
||||
use sc_network::{network_state::NetworkState, NetworkStatus};
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
use sp_runtime::traits::{Block as BlockT, Header};
|
||||
use sp_transaction_pool::TransactionPool;
|
||||
use sp_utils::mpsc::TracingUnboundedReceiver;
|
||||
use std::fmt::Display;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
mod display;
|
||||
|
||||
/// The format to print telemetry output in.
|
||||
#[derive(PartialEq)]
|
||||
pub enum OutputFormat {
|
||||
Coloured,
|
||||
Plain,
|
||||
#[derive(Clone)]
|
||||
pub struct OutputFormat {
|
||||
/// Enable color output in logs.
|
||||
pub enable_color: bool,
|
||||
/// Add a prefix before every log line
|
||||
pub prefix: String,
|
||||
}
|
||||
|
||||
/// Creates an informant in the form of a `Future` that must be polled regularly.
|
||||
pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futures::Future<Output = ()> {
|
||||
let client = service.client();
|
||||
let pool = service.transaction_pool();
|
||||
/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = "unknown")`.
|
||||
#[cfg(target_os = "unknown")]
|
||||
pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool {}
|
||||
|
||||
let mut display = display::InformantDisplay::new(format);
|
||||
/// Marker trait for a type that implements `TransactionPool` and `MallocSizeOf` on `not(target_os = "unknown")`.
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub trait TransactionPoolAndMaybeMallogSizeOf: TransactionPool + MallocSizeOf {}
|
||||
|
||||
let display_notifications = service
|
||||
.network_status(Duration::from_millis(5000))
|
||||
#[cfg(target_os = "unknown")]
|
||||
impl<T: TransactionPool> TransactionPoolAndMaybeMallogSizeOf for T {}
|
||||
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
impl<T: TransactionPool + MallocSizeOf> TransactionPoolAndMaybeMallogSizeOf for T {}
|
||||
|
||||
/// Builds the informant and returns a `Future` that drives the informant.
|
||||
pub fn build<B: BlockT, C>(
|
||||
client: Arc<C>,
|
||||
network_status_stream_builder: impl FnOnce(
|
||||
Duration,
|
||||
) -> TracingUnboundedReceiver<(
|
||||
NetworkStatus<B>,
|
||||
NetworkState,
|
||||
)>,
|
||||
pool: Arc<impl TransactionPoolAndMaybeMallogSizeOf>,
|
||||
format: OutputFormat,
|
||||
) -> impl futures::Future<Output = ()>
|
||||
where
|
||||
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
|
||||
<C as HeaderMetadata<B>>::Error: Display,
|
||||
{
|
||||
let mut display = display::InformantDisplay::new(format.clone());
|
||||
|
||||
let client_1 = client.clone();
|
||||
let display_notifications = network_status_stream_builder(Duration::from_millis(5000))
|
||||
.for_each(move |(net_status, _)| {
|
||||
let info = client.usage_info();
|
||||
let info = client_1.usage_info();
|
||||
if let Some(ref usage) = info.usage {
|
||||
trace!(target: "usage", "Usage statistics: {}", usage);
|
||||
} else {
|
||||
@@ -64,7 +97,6 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur
|
||||
future::ready(())
|
||||
});
|
||||
|
||||
let client = service.client();
|
||||
let mut last_best = {
|
||||
let info = client.usage_info();
|
||||
Some((info.chain.best_number, info.chain.best_hash))
|
||||
@@ -82,7 +114,8 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur
|
||||
|
||||
match maybe_ancestor {
|
||||
Ok(ref ancestor) if ancestor.hash != *last_hash => info!(
|
||||
"♻️ Reorg on #{},{} to #{},{}, common ancestor #{},{}",
|
||||
"♻️ {}Reorg on #{},{} to #{},{}, common ancestor #{},{}",
|
||||
format.prefix,
|
||||
Colour::Red.bold().paint(format!("{}", last_num)), last_hash,
|
||||
Colour::Green.bold().paint(format!("{}", n.header.number())), n.hash,
|
||||
Colour::White.bold().paint(format!("{}", ancestor.number)), ancestor.hash,
|
||||
@@ -97,7 +130,13 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur
|
||||
last_best = Some((n.header.number().clone(), n.hash.clone()));
|
||||
}
|
||||
|
||||
info!(target: "substrate", "✨ Imported #{} ({})", Colour::White.bold().paint(format!("{}", n.header.number())), n.hash);
|
||||
info!(
|
||||
target: "substrate",
|
||||
"✨ {}Imported #{} ({})",
|
||||
format.prefix,
|
||||
Colour::White.bold().paint(format!("{}", n.header.number())),
|
||||
n.hash,
|
||||
);
|
||||
future::ready(())
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user