From 229070beb6bea8c9b1d03485d15a4b28508c76e5 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 13 Jul 2022 14:45:40 +0200 Subject: [PATCH 1/2] appender: name spawned thread I find it useful when debugging applications with lots of threads to easily identity them by their names. --- tracing-appender/src/worker.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tracing-appender/src/worker.rs b/tracing-appender/src/worker.rs index c675e6b47b..a6919c4c91 100644 --- a/tracing-appender/src/worker.rs +++ b/tracing-appender/src/worker.rs @@ -68,20 +68,23 @@ impl Worker { /// Creates a worker thread that processes a channel until it's disconnected pub(crate) fn worker_thread(mut self) -> std::thread::JoinHandle<()> { - thread::spawn(move || { - loop { - match self.work() { - Ok(WorkerState::Continue) | Ok(WorkerState::Empty) => {} - Ok(WorkerState::Shutdown) | Ok(WorkerState::Disconnected) => { - drop(self.writer); // drop now in case it blocks - let _ = self.shutdown.recv(); - return; - } - Err(_) => { - // TODO: Expose a metric for IO Errors, or print to stderr + thread::Builder::new() + .name("tracing-appender".to_string()) + .spawn(move || { + loop { + match self.work() { + Ok(WorkerState::Continue) | Ok(WorkerState::Empty) => {} + Ok(WorkerState::Shutdown) | Ok(WorkerState::Disconnected) => { + drop(self.writer); // drop now in case it blocks + let _ = self.shutdown.recv(); + return; + } + Err(_) => { + // TODO: Expose a metric for IO Errors, or print to stderr + } } } - } - }) + }) + .expect("failed to spawn thread") } } From 044302b4466526c2ca7a0d2a2868fe3b44ce6960 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 13 Jul 2022 12:00:43 -0700 Subject: [PATCH 2/2] clarify what was being spawned in `expect` message --- tracing-appender/src/worker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing-appender/src/worker.rs b/tracing-appender/src/worker.rs index a6919c4c91..00012d518c 100644 --- a/tracing-appender/src/worker.rs +++ b/tracing-appender/src/worker.rs @@ -85,6 +85,6 @@ impl Worker { } } }) - .expect("failed to spawn thread") + .expect("failed to spawn `tracing-appender` non-blocking worker thread") } }