mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00
appender: name spawned thread (#2219)
## Motivation I find it useful when debugging applications with lots of threads to easily identity them by their names. ## Solution Just name the thread as other crates such as `sentry-rust` are doing. Co-authored-by: Guillaume Desmottes <guillaume@desmottes.be>
This commit is contained in:
parent
7533872af0
commit
21cdf08e15
@ -68,22 +68,25 @@ impl<T: Write + Send + Sync + 'static> Worker<T> {
|
|||||||
|
|
||||||
/// Creates a worker thread that processes a channel until it's disconnected
|
/// Creates a worker thread that processes a channel until it's disconnected
|
||||||
pub(crate) fn worker_thread(mut self) -> std::thread::JoinHandle<()> {
|
pub(crate) fn worker_thread(mut self) -> std::thread::JoinHandle<()> {
|
||||||
thread::spawn(move || {
|
thread::Builder::new()
|
||||||
loop {
|
.name("tracing-appender".to_string())
|
||||||
match self.work() {
|
.spawn(move || {
|
||||||
Ok(WorkerState::Continue) | Ok(WorkerState::Empty) => {}
|
loop {
|
||||||
Ok(WorkerState::Shutdown) | Ok(WorkerState::Disconnected) => {
|
match self.work() {
|
||||||
let _ = self.shutdown.recv();
|
Ok(WorkerState::Continue) | Ok(WorkerState::Empty) => {}
|
||||||
break;
|
Ok(WorkerState::Shutdown) | Ok(WorkerState::Disconnected) => {
|
||||||
}
|
let _ = self.shutdown.recv();
|
||||||
Err(_) => {
|
break;
|
||||||
// TODO: Expose a metric for IO Errors, or print to stderr
|
}
|
||||||
|
Err(_) => {
|
||||||
|
// TODO: Expose a metric for IO Errors, or print to stderr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if let Err(e) = self.writer.flush() {
|
||||||
if let Err(e) = self.writer.flush() {
|
eprintln!("Failed to flush. Error: {}", e);
|
||||||
eprintln!("Failed to flush. Error: {}", e);
|
}
|
||||||
}
|
})
|
||||||
})
|
.expect("failed to spawn `tracing-appender` non-blocking worker thread")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user