You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to display the timestamp depending on the log level but the API makes this harder than expected.
In the Format methods there are a bunch of methods of the form with_xxx(self, bool). But the method that allows enabling or disabling the timestamps breaks this pattern by being called without_time(self) and not accepting a boolean.
Additionally, calling without_time changes the type, so its not as simple as just breaking up the builder to add an if.
let format = fmt::format().with_level(true).with_target(show_log_details).with_thread_ids(false).with_thread_names(false).with_timestamp(show_log_details).compact();
tracing_subscriber::fmt().event_format(format).with_max_level(verbosity).init();
Current solution:
let show_log_details = matches!(verbosity,Verbosity::Debug | Verbosity::Trace);let format = fmt::format().with_level(true).with_target(show_log_details).with_thread_ids(false).with_thread_names(false).compact();if show_log_details {
tracing_subscriber::fmt().event_format(format).with_max_level(verbosity).init();}else{let format = format.without_time();
tracing_subscriber::fmt().event_format(format).with_max_level(verbosity).init();}
I saw that there was an open PR to fix this: #2084 but it hasn't received any updates since 2022.
The text was updated successfully, but these errors were encountered:
azerupi
changed the title
Format::without_time seems to break the pattern by not accepting a boolean
Format::without_time makes it hard to enable/disable timestamps at runtime
Dec 30, 2024
Bug Report
Version
But this is also present in master.
Crates
Description
I'm trying to display the timestamp depending on the log level but the API makes this harder than expected.
In the
Format
methods there are a bunch of methods of the formwith_xxx(self, bool)
. But the method that allows enabling or disabling the timestamps breaks this pattern by being calledwithout_time(self)
and not accepting a boolean.Additionally, calling
without_time
changes the type, so its not as simple as just breaking up the builder to add an if.https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/format/struct.Format.html#method.without_time
Desired:
Current solution:
I saw that there was an open PR to fix this: #2084 but it hasn't received any updates since 2022.
The text was updated successfully, but these errors were encountered: