mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Add logger configuration hook (#10440)
* Initial poc Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Make config available to logger hook Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fmt Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fmt Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Add metric prefix option in sc_cli::RunCmd Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Remove print Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Review fixes Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fmt Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix docs Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
@@ -581,10 +581,40 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
/// This method:
|
||||
///
|
||||
/// 1. Sets the panic handler
|
||||
/// 2. Optionally customize logger/profiling
|
||||
/// 2. Initializes the logger
|
||||
/// 3. Raises the FD limit
|
||||
fn init<C: SubstrateCli>(&self) -> Result<()> {
|
||||
sp_panic_handler::set(&C::support_url(), &C::impl_version());
|
||||
///
|
||||
/// The `logger_hook` closure is executed before the logger is constructed
|
||||
/// and initialized. It is useful for setting up a custom profiler.
|
||||
///
|
||||
/// Example:
|
||||
/// ```
|
||||
/// use sc_tracing::{SpanDatum, TraceEvent};
|
||||
/// struct TestProfiler;
|
||||
///
|
||||
/// impl sc_tracing::TraceHandler for TestProfiler {
|
||||
/// fn handle_span(&self, sd: &SpanDatum) {}
|
||||
/// fn handle_event(&self, _event: &TraceEvent) {}
|
||||
/// };
|
||||
///
|
||||
/// fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () {
|
||||
/// |logger_builder, config| {
|
||||
/// logger_builder.with_custom_profiling(Box::new(TestProfiler{}));
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
fn init<F>(
|
||||
&self,
|
||||
support_url: &String,
|
||||
impl_version: &String,
|
||||
logger_hook: F,
|
||||
config: &Configuration,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnOnce(&mut LoggerBuilder, &Configuration),
|
||||
{
|
||||
sp_panic_handler::set(support_url, impl_version);
|
||||
|
||||
let mut logger = LoggerBuilder::new(self.log_filters()?);
|
||||
logger
|
||||
@@ -600,6 +630,9 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
logger.with_colors(false);
|
||||
}
|
||||
|
||||
// Call hook for custom profiling setup.
|
||||
logger_hook(&mut logger, &config);
|
||||
|
||||
logger.init()?;
|
||||
|
||||
if let Some(new_limit) = fdlimit::raise_fd_limit() {
|
||||
|
||||
Reference in New Issue
Block a user