Skip to content

Commit

Permalink
Log messages print the system TreadID on linux-like systems
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Feb 21, 2024
1 parent 6001f53 commit 026c9d9
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,31 @@ pub extern "C" fn zc_init_logger_opts(opts: Option<&zc_init_logger_options_t>) {
.format(move |buf, record| {
write!(buf, "[{} {:<5}", buf.timestamp(), record.level(),)?;
if pid {
write!(buf, " {:>6}", std::process::id(),)?;
write!(buf, " {:>7}", std::process::id(),)?;
}
if tid {
write!(
buf,
" {:>6}",
&format!("{:?}", std::thread::current().id())[8..],
)?;
#[cfg(any(
target_os = "linux",
target_os = "l4re",
target_os = "android",
target_os = "emscripten"
))]
{
write!(buf, " {:>7}", unsafe { libc::syscall(libc::SYS_gettid) },)?;
}
#[cfg(not(any(
target_os = "linux",
target_os = "l4re",
target_os = "android",
target_os = "emscripten"
)))]
{
write!(
buf,
" {:>7}",
&format!("{:?}", std::thread::current().id())[8..],
)?;
}
}
writeln!(buf, " {}] {}", record.target(), record.args(),)
})
Expand Down

0 comments on commit 026c9d9

Please sign in to comment.