feat(log): Log the tracing level when it is set or reloaded (#4515)
* Log the tracing level when it is set or reloaded * Add the `log` crate as a direct dependency * Make `log` required
This commit is contained in:
parent
95f14ffdcd
commit
77d9d8f017
|
|
@ -6520,6 +6520,7 @@ dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"inferno",
|
"inferno",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"log",
|
||||||
"metrics",
|
"metrics",
|
||||||
"metrics-exporter-prometheus",
|
"metrics-exporter-prometheus",
|
||||||
"num-integer",
|
"num-integer",
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ rand = { version = "0.8.5", package = "rand" }
|
||||||
sentry-tracing = { version = "0.23.0", optional = true }
|
sentry-tracing = { version = "0.23.0", optional = true }
|
||||||
sentry = { version = "0.23.0", default-features = false, features = ["backtrace", "contexts", "reqwest", "rustls"], optional = true }
|
sentry = { version = "0.23.0", default-features = false, features = ["backtrace", "contexts", "reqwest", "rustls"], optional = true }
|
||||||
|
|
||||||
|
# zebrad uses tracing for logging,
|
||||||
|
# we only use `log` to print the static log levels in transitive dependencies
|
||||||
|
log = "0.4.14"
|
||||||
|
|
||||||
# test feature proptest-impl
|
# test feature proptest-impl
|
||||||
proptest = { version = "0.10.1", optional = true }
|
proptest = { version = "0.10.1", optional = true }
|
||||||
proptest-derive = { version = "0.3.0", optional = true }
|
proptest-derive = { version = "0.3.0", optional = true }
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl Tracing {
|
||||||
// Construct a tracing subscriber with the supplied filter and enable reloading.
|
// Construct a tracing subscriber with the supplied filter and enable reloading.
|
||||||
let builder = FmtSubscriber::builder()
|
let builder = FmtSubscriber::builder()
|
||||||
.with_ansi(use_color)
|
.with_ansi(use_color)
|
||||||
.with_env_filter(filter)
|
.with_env_filter(&filter)
|
||||||
.with_filter_reloading();
|
.with_filter_reloading();
|
||||||
let filter_handle = builder.reload_handle();
|
let filter_handle = builder.reload_handle();
|
||||||
|
|
||||||
|
|
@ -62,6 +62,13 @@ impl Tracing {
|
||||||
(Some(layer1), Some(layer2)) => subscriber.with(layer1).with(layer2).init(),
|
(Some(layer1), Some(layer2)) => subscriber.with(layer1).with(layer2).init(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
?filter,
|
||||||
|
TRACING_STATIC_MAX_LEVEL = ?tracing::level_filters::STATIC_MAX_LEVEL,
|
||||||
|
LOG_STATIC_MAX_LEVEL = ?log::STATIC_MAX_LEVEL,
|
||||||
|
"started tracing component",
|
||||||
|
);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
filter_handle,
|
filter_handle,
|
||||||
flamegrapher,
|
flamegrapher,
|
||||||
|
|
@ -79,9 +86,19 @@ impl Tracing {
|
||||||
///
|
///
|
||||||
/// This can be used to provide a dynamic tracing filter endpoint.
|
/// This can be used to provide a dynamic tracing filter endpoint.
|
||||||
pub fn reload_filter(&self, filter: impl Into<EnvFilter>) {
|
pub fn reload_filter(&self, filter: impl Into<EnvFilter>) {
|
||||||
|
let filter = filter.into();
|
||||||
|
let filter_str = filter.to_string();
|
||||||
|
|
||||||
self.filter_handle
|
self.filter_handle
|
||||||
.reload(filter)
|
.reload(filter)
|
||||||
.expect("the subscriber is not dropped before the component is");
|
.expect("the subscriber is not dropped before the component is");
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
filter = ?filter_str,
|
||||||
|
TRACING_STATIC_MAX_LEVEL = ?tracing::level_filters::STATIC_MAX_LEVEL,
|
||||||
|
LOG_STATIC_MAX_LEVEL = ?log::STATIC_MAX_LEVEL,
|
||||||
|
"reloaded tracing filter",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue