Log to a tracing::Subscriber explicitly

I'm writing an async rust crate and i want users of it to be able to provide a tracing::Subscriber explicitly, and have all messages go to that instead of the default subscriber (is that per-thread? that seems like it would interact poorly with async)

none of the macros seem to have a subscriber paramater, although span::with_subscriber or Dispatch seem like they might work.

Would tracing::subscriber::with_default be an acceptable solution for you? There is also the tracing::subscriber::set_default function if you prefer a RAII-based approach over callbacks. Both will create a thread-local subscriber (unlike tracing::subscriber::set_global_default).

thread local is a problem with tokio, where a task is multiplexed across multiple threads.

i ended up using tracing::Instrument.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.