Skip to content

Commit 33f27d1

Browse files
committed
fix: Handle missing time offsets gracefully
The tracing_subscribe docs state that missing offsets likely mean that we're in a multithreaded context: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.OffsetTime.html#method.local_rfc_3339 We're not in a multithreaded context at this point, but some platforms (e.g. OpenBSD) still don't have time offsets available. Since this is only a rust-analyzer debugging convenience, just use system time logging in this situation. Fixes rust-lang#18384
1 parent 1fbaccd commit 33f27d1

File tree

1 file changed

+14
-6
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src/tracing

1 file changed

+14
-6
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/tracing/config.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,22 @@ where
5858
let writer = self.writer;
5959

6060
let ra_fmt_layer = tracing_subscriber::fmt::layer()
61-
.with_timer(
62-
time::OffsetTime::local_rfc_3339()
63-
.expect("Could not get local offset, make sure you're on the main thread"),
64-
)
6561
.with_target(false)
6662
.with_ansi(false)
67-
.with_writer(writer)
68-
.with_filter(targets_filter);
63+
.with_writer(writer);
64+
65+
let ra_fmt_layer = match time::OffsetTime::local_rfc_3339() {
66+
Ok(timer) => {
67+
// If we can get the time offset, format logs with the timezone.
68+
ra_fmt_layer.with_timer(timer).boxed()
69+
}
70+
Err(_) => {
71+
// Use system time if we can't get the time offset. This should
72+
// never happen on Linux, but can happen on e.g. OpenBSD.
73+
ra_fmt_layer.boxed()
74+
}
75+
}
76+
.with_filter(targets_filter);
6977

7078
let chalk_layer = match self.chalk_filter {
7179
Some(chalk_filter) => {

0 commit comments

Comments
 (0)