mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00

Currently there is no good way to get timestamped log entries with the `tracing-fmt` subscriber. Even with `full`, timestamps are not included. This is surprising to those coming from other logging crates. It is also inconvenient to work around, as you would either need to add a custom field to _all_ spans and events across all your crates, or write your own subscriber which sort of reduces the usefulness of `fmt`. This patch introduces a trait for event formatters (`FormatEvent`) so that it is easier to write more complex formatters (previously they were just `Fn(...) -> fmt::Result` which would require boxing a closure to produce). It then implements this new trait for `default::Format`, which is the new default formatter. It implements "compact"/full formatting exactly like before, except that is also generic over a timer. The timer must implement `default::FormatTime`, which has a single method that writes the current time out to a `fmt::Write`. This method is implemented for a two new unit structs `SystemTime` and `Uptime`. `SystemTime` is pretty-printed using `chrono` with the new default feature `chrono`, and `Debug` of `std::net::SystemTime` is used if the feature is turned off. `Uptime` prints the fractional number of seconds since an epoch. Users can also provide `()` as the time formatter to not produce timestamps in logged entries (accessible through `default::Format::without_time`). This patch also switches the default output to the verbose format, with `compact` offered to return to the compact output format. Closes #94.