-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
None-layers resets loglevel #2265
Comments
Noted that if I change the order of these filters it works as expected: let layer = tracing_subscriber::fmt::layer()
.with_filter(filter::LevelFilter::DEBUG)
.with_filter(SomeFilter); And it also works as expected(?) if I implement |
I should also mention that if I remove |
This actually seems to have to do with layers that have max_level_hint set to The same issue occurs with this code, here the outermost layer have log level set to OFF, then a middle layer where it is set to None, and an inner layer set to DEBUG. It will not print any log rows. But if we remove the middle layer, INFO and DEBUG logs are printed. use tracing::{debug, dispatcher, info, metadata::LevelFilter, trace};
use tracing_subscriber::{
self, filter, layer::Context, prelude::__tracing_subscriber_SubscriberExt, Layer, Registry,
};
pub struct MyLayer {
level: Option<filter::LevelFilter>,
}
impl MyLayer {
fn new(level: Option<filter::LevelFilter>) -> Self {
Self { level }
}
}
impl<S: tracing::Subscriber> Layer<S> for MyLayer {
fn enabled(&self, _metadata: &tracing::Metadata<'_>, _ctx: Context<'_, S>) -> bool {
true
}
fn max_level_hint(&self) -> Option<filter::LevelFilter> {
self.level
}
}
fn main() {
let layer = tracing_subscriber::fmt::layer().with_filter(filter::LevelFilter::DEBUG);
let subscriber = Registry::default()
.with(layer)
.with(MyLayer::new(None))
.with(MyLayer::new(Some(LevelFilter::OFF)));
dispatcher::set_global_default(dispatcher::Dispatch::new(subscriber)).unwrap();
info!("info about yaks");
debug!("debug about yaks");
trace!("trace about yaks");
} So I wonder if this actually have to do with the Something like this https://github.com/tokio-rs/tracing/compare/master...EmbarkStudios:tracing:fredr/layered-pick-inner-hint?expand=1 That at least seems to solve my edge case, and tests seems to pass, but I'm in over my head a bit here Edit: This was a bit of a side track, while it solves the problem for the repro above, it doesnt for our real application. |
@fredr do you mind telling me what |
Hey @guswynn, sorry for making this issue more complicated than it needed to be. The A difference in the result between our real app and the example code is that the example code gets reset to
|
I believe I'm hitting the same issue. I have the following code: let profiling_layer = if env::var_os("BXT_RS_PROFILE").is_some() {
let (chrome_layer, guard) = tracing_chrome::ChromeLayerBuilder::new()
.file("trace.json")
.include_args(true)
.include_locations(false)
.build();
Box::leak(Box::new(guard));
Some(chrome_layer)
} else {
None
};
tracing_subscriber::registry()
.with(file_layer)
.with(profiling_layer)
// Term layer must be last, otherwise the log file will have some ANSI codes:
// https://github.com/tokio-rs/tracing/issues/1817
.with(term_layer)
.init(); When |
After a recent tracing update, using a None layer prevents it from outputting any events. tokio-rs/tracing#2265
I'm using: tracing = "0.1.36"
tracing-chrome = "0.6.0"
tracing-subscriber = "0.3.15"
|
We have this exact problem in Prisma. All logs disappeared when doing a routine Our logger code is kind of complex, and I haven't found a workaround yet: For now, I'm downgrading to 0.3.11. I'd be happy to find a workaround, but also would be great if breaking changes like this would actually change the major version, so we can still |
Sorry about the delayed response here eveyone: I did find time to look deeper into this and believe to have found the culprit broken code in the I believe there is also a simple-ish workaround (attaching a blank filter), but I will need to test this sometime this week. |
@guswynn any updates on the fix for this? Happy to help get it through! |
@hawkw the fix is basically to add this passes all tests except for 1 test on the fmt layer, which is that |
@hawkw here is my test branch:https://github.com/guswynn/tracing/tree/option-test |
) ## Motivation Currently, when using the `Subscribe` impl for `Option<S: Subscribe<...>>`, the `Subscribe::max_level_hint` returns `Some(LevelFilter::OFF)`. This was intended to allow totally disabling output in the case where a collector is composed entirely of `None` subscribers. However, when other subscribers *do* exist but return `None` from their `max_level_hint` implementations to indicate that they don't care what the max level is, the presence of a single `None` layer will globally disable everything, which is not the wanted behavior. Fixes #2265 ## Solution This branch introduces a special downcast marker that can be used to detect when a `Subscribe` in a `Layered` is `None`. This allows the `pick_level_hint` method to short-circuit when a `Subscribe` implementation which is `None` returns `Some(LevelFilter::OFF)` from its `max_level_hint` if the other half of the `Layered` is not `None`. The tests I added should be pretty thorough! Additionally, the downcast marker is special-cased in the `reload` subscriber. Normally, this subscriber doesn't support downcasting, but it can in the case of the special marker value. Co-authored-by: Eliza Weisman <eliza@buoyant.io>
## Motivation Currently, when using the `Layer` impl for `Option<S: Layer<...>>`, the `Layer::max_level_hint` returns `Some(LevelFilter::OFF)`. This was intended to allow totally disabling output in the case where a `Subscriber` is composed entirely of `None` `Layer`s. However, when other `Layer`s *do* exist but return `None` from their `max_level_hint` implementations to indicate that they don't care what the max level is, the presence of a single `None` layer will globally disable everything, which is not the wanted behavior. Fixes #2265 ## Solution This branch introduces a special downcast marker that can be used to detect when a `Layer` in a `Layered` is `None`. This allows the `pick_level_hint` method to short-circuit when a `Layer` implementation which is `None` returns `Some(LevelFilter::OFF)` from its `max_level_hint` if the other half of the `Layered` is not `None`. The tests I added should be pretty thorough! Additionally, the downcast marker is special-cased in the `reload` `Layer`. Normally, this `Layer` doesn't support downcasting, but it can in the case of the special marker value. Co-authored-by: Eliza Weisman <eliza@buoyant.io>
## Motivation Currently, when using the `Layer` impl for `Option<S: Layer<...>>`, the `Layer::max_level_hint` returns `Some(LevelFilter::OFF)`. This was intended to allow totally disabling output in the case where a `Subscriber` is composed entirely of `None` `Layer`s. However, when other `Layer`s *do* exist but return `None` from their `max_level_hint` implementations to indicate that they don't care what the max level is, the presence of a single `None` layer will globally disable everything, which is not the wanted behavior. Fixes #2265 ## Solution This branch introduces a special downcast marker that can be used to detect when a `Layer` in a `Layered` is `None`. This allows the `pick_level_hint` method to short-circuit when a `Layer` implementation which is `None` returns `Some(LevelFilter::OFF)` from its `max_level_hint` if the other half of the `Layered` is not `None`. The tests I added should be pretty thorough! Additionally, the downcast marker is special-cased in the `reload` `Layer`. Normally, this `Layer` doesn't support downcasting, but it can in the case of the special marker value. Co-authored-by: Eliza Weisman <eliza@buoyant.io>
…s#2321) ## Motivation Currently, when using the `Layer` impl for `Option<S: Layer<...>>`, the `Layer::max_level_hint` returns `Some(LevelFilter::OFF)`. This was intended to allow totally disabling output in the case where a `Subscriber` is composed entirely of `None` `Layer`s. However, when other `Layer`s *do* exist but return `None` from their `max_level_hint` implementations to indicate that they don't care what the max level is, the presence of a single `None` layer will globally disable everything, which is not the wanted behavior. Fixes tokio-rs#2265 ## Solution This branch introduces a special downcast marker that can be used to detect when a `Layer` in a `Layered` is `None`. This allows the `pick_level_hint` method to short-circuit when a `Layer` implementation which is `None` returns `Some(LevelFilter::OFF)` from its `max_level_hint` if the other half of the `Layered` is not `None`. The tests I added should be pretty thorough! Additionally, the downcast marker is special-cased in the `reload` `Layer`. Normally, this `Layer` doesn't support downcasting, but it can in the case of the special marker value. Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Bug Report
Version
Platform
Crates
tracing-subscriber
Description
#2195 causes our log level to be set to off when having a None-layer in our chain. This is a bit of an edge case, and I might have a bit of an unholy setup. But I would expect the following code to print out debug and info, but it prints out nothing (in tracing-subscriber v0.3.11 this works as I expect it to).
Here is a minimal repro of my problem:
In reality the optional layer is a tokio console, and
SomeFilter
filters out things based on metadata, like target, and the loglevel is set via a cli flag.If I change the
Layer
implementation ofOption
in tracing-subscriber to the following it all works as expected:However, that is the reverse of what the mentioned pr does, so I'm not sure what the solution is here. Is this a bug, or are we doing something strange with our setup?
The text was updated successfully, but these errors were encountered: