Skip to content

Commit eb78aa0

Browse files
authored
Return 0 for thread_id on unsupported targets (#21)
1 parent e8bb63b commit eb78aa0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/formatter.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ fn default_enable_ansi_color() -> bool {
7474

7575
/// Gets the current thread id as an integer
7676
///
77-
/// This only supports the normal platforms here, I doubt this crate has wide usage,
78-
/// we just hard compile fail if targeting a platform we don't implement so
79-
/// that it is obvious
77+
/// This only supports the normal platforms here (Linux, Windows, Apple).
78+
/// For anything else like WASM we just return 0.
8079
///
8180
/// Note that a Rust `ThreadId` is actually just a process specific atomic,
8281
/// completely unrelated to the thread id assigned by the operating system, but
@@ -121,6 +120,15 @@ fn current_thread_id() -> u64 {
121120

122121
id
123122
}
123+
124+
#[cfg(not(any(
125+
any(target_os = "linux", target_os = "android"),
126+
target_os = "windows",
127+
target_vendor = "apple"
128+
)))]
129+
{
130+
0
131+
}
124132
}
125133

126134
impl<S, N> FormatEvent<S, N> for EventsFormatter

src/formatter/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ impl Builder {
7777
self
7878
}
7979

80+
/// Enable emitting the thread id in log output.
81+
///
82+
/// Note: On unsupported targets like WASM, the thread id will be `0`.
8083
pub fn with_thread_ids(mut self, enable: bool) -> Self {
8184
self.events.with_thread_ids = enable;
8285
self

0 commit comments

Comments
 (0)