Replies: 1 comment 1 reply
-
You could just create a custom Layer (https://docs.rs/tracing-subscriber/latest/tracing_subscriber/layer/index.html) and then check a task_local storage (https://docs.rs/tokio/latest/tokio/macro.task_local.html) in the struct CustomSubscriber {}
impl<S: Subscriber> Layer<S> for CustomSubscriber {
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
LOG.with(|flag| {
if *flag {
// log
}
})
}
}
fn main() {
tracing_subscriber::registry()
.with(CustomSubscriber {})
.init();
let _ = std::thread::spawn(|| {
LOG.sync_scope(true, || {
tracing::info!("info");
})
})
.join();
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently using tracing for a program where 10 threads are run all at the same time. A ton of logs are emitted asynchronously so there's a lot of noise from each thread's logs being shoved together out of order. I wanted to ask if there's an easy way to separate logs by thread? I need to do this in order to debug my program. I hacked together some code to accomplish this but it randomly crashes because it tries to
drop
a span that doesn't exist.My current approach is to just generate a subscriber like so:
and use it in the method that each thread runs like so:
Beta Was this translation helpful? Give feedback.
All reactions