Description
Bug Report
Version
tracing-subscriber
0.2.7
Crates
tracing-subscriber
Description
By default, tracing-subscriber
's fmt
module uses the chrono
crate for formatting timestamps. However, the chrono dependency is optional and can be disabled independently of fmt
. This is correct --- users who are using the Uptime
timestamp formatter, providing their own custom timestamp formatter, or not using timestamps don't need the chrono
dependency and may want to disable it.
However, when the chrono
feature flag is disabled, the default formatter still enables SystemTime
timestamps by default:
tracing/tracing-subscriber/src/fmt/format/mod.rs
Lines 184 to 194 in 7dc37dd
So, the formatter will still emit timestamps unless
without_time(true)
is called.
What do we do when timestamps are enabled, but we can't use chrono
to format them because the dependency is not enabled?
It turns out that we fall back to SystemTime
's fmt::Debug
impl:
tracing/tracing-subscriber/src/fmt/time.rs
Lines 119 to 124 in 7dc37dd
The formatted output from this is...not great:
I do think it's correct to rely on chrono
(or arbitrary user-defined timestamp formatters) for complex human-readable formatting. But the fmt::Debug
implementation is not ideal. It includes the struct's name, field names, and curly braces, which add a lot of noise and make the log lines much longer. It leaks the SystemTime
type's internal layout, which may be different depending on OS. And, the width of the numeric fields are not padded to a fixed width, so the log lines are not aligned.
We should try to fall back to something a little nicer when chrono
isn't present. It doesn't need to be fancy --- we can (and should!) rely on chrono
for human readable formats. Maybe just the number of seconds since the Unix epoch or something?