-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: add OffsetTime workaround for local offset (#1772)
## Motivation Currently, the `time` crate refuses to determine the local timezone offset on Unix unless the program is single-threaded or the `unsound_local_offset` feature is enabled. Because `LocalTime` determines the local timezone offset every time it formats a message, and `tracing` is frequently used in multi-threaded programs, `LocalTime` effectively requires `unsound_local_offset`. `unsound_local_offset` is inconvenient to enable and potentially dangerous. ## Solution Add an `OffsetTime` formatter that formats time with a fixed offset, passed in when it is initialized. Make it convenient to initialize this with the local timezone offset. The main advantage of this formatter over `LocalTime` is that if it is initialized early, it will succeed without `unsound_local_offset`. An additional advantage is that the program can handle errors determining the local offset, because they now occur in the program's initialization code rather than in tracing's formatting code. This is not a drop-in replacement for LocalTime, because it behaves differently if the program keeps running across a DST change. `LocalTime` will pick up the new local offset, while `OffsetTime` will continue to use the offset in effect when the program started. Fixes #1771
- Loading branch information
Showing
2 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters