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:
sandreim
2021-12-16 13:18:24 +02:00
committed by GitHub
parent f99307b600
commit 9b73a8a6fc
7 changed files with 148 additions and 41 deletions
+23 -2
View File
@@ -193,6 +193,7 @@ where
pub struct LoggerBuilder {
directives: String,
profiling: Option<(crate::TracingReceiver, String)>,
custom_profiler: Option<Box<dyn crate::TraceHandler>>,
log_reloading: bool,
force_colors: Option<bool>,
detailed_output: bool,
@@ -204,6 +205,7 @@ impl LoggerBuilder {
Self {
directives: directives.into(),
profiling: None,
custom_profiler: None,
log_reloading: false,
force_colors: None,
detailed_output: false,
@@ -220,6 +222,15 @@ impl LoggerBuilder {
self
}
/// Add a custom profiler.
pub fn with_custom_profiling(
&mut self,
custom_profiler: Box<dyn crate::TraceHandler>,
) -> &mut Self {
self.custom_profiler = Some(custom_profiler);
self
}
/// Wether or not to disable log reloading.
pub fn with_log_reloading(&mut self, enabled: bool) -> &mut Self {
self.log_reloading = enabled;
@@ -256,7 +267,12 @@ impl LoggerBuilder {
self.detailed_output,
|builder| enable_log_reloading!(builder),
)?;
let profiling = crate::ProfilingLayer::new(tracing_receiver, &profiling_targets);
let mut profiling =
crate::ProfilingLayer::new(tracing_receiver, &profiling_targets);
self.custom_profiler
.into_iter()
.for_each(|profiler| profiling.add_handler(profiler));
tracing::subscriber::set_global_default(subscriber.with(profiling))?;
@@ -269,7 +285,12 @@ impl LoggerBuilder {
self.detailed_output,
|builder| builder,
)?;
let profiling = crate::ProfilingLayer::new(tracing_receiver, &profiling_targets);
let mut profiling =
crate::ProfilingLayer::new(tracing_receiver, &profiling_targets);
self.custom_profiler
.into_iter()
.for_each(|profiler| profiling.add_handler(profiler));
tracing::subscriber::set_global_default(subscriber.with(profiling))?;