summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-12-02 04:53:31 -0500
committerGitHub <noreply@github.com>2023-12-02 04:53:31 -0500
commitfab86e833a89b2227d052f80eb1bf250a68eb60e (patch)
tree74ac688f2b8c2f304c07d85c03be6d4cbc03ed95 /src
parent074b205a825c49280f7944efd9bf6f0af6d1155d (diff)
other: add back local time in debug logs (#1346)
* other: add back local time in debug logs This still has a UTC fallback. * cleanup and some warnings
Diffstat (limited to 'src')
-rw-r--r--src/utils/logging.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/utils/logging.rs b/src/utils/logging.rs
index 312c909f..3b405ad7 100644
--- a/src/utils/logging.rs
+++ b/src/utils/logging.rs
@@ -1,16 +1,37 @@
#[cfg(feature = "logging")]
+pub static OFFSET: once_cell::sync::Lazy<time::UtcOffset> = once_cell::sync::Lazy::new(|| {
+ use time::util::local_offset::Soundness;
+
+ // SAFETY: We only invoke this once, quickly, and it should be invoked in a single-thread context.
+ // We also should only ever hit this logging at all in a debug context which is generally fine,
+ // release builds should have this logging disabled entirely for now.
+ unsafe {
+ // XXX: If we ever DO add general logging as a release feature, evaluate this again and whether this is
+ // something we want enabled in release builds! What might be safe is falling back to the non-set-soundness
+ // mode when specifically using certain feature flags (e.g. dev-logging feature enables this behaviour).
+
+ time::util::local_offset::set_soundness(Soundness::Unsound);
+ let res = time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC);
+ time::util::local_offset::set_soundness(Soundness::Sound);
+
+ res
+ }
+});
+
+#[cfg(feature = "logging")]
pub fn init_logger(
min_level: log::LevelFilter, debug_file_name: &std::ffi::OsStr,
) -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(|out, message, record| {
- // Note we aren't using local time since it only works on single-threaded processes.
- // If that ever does get patched in again, enable the "local-offset" feature.
- let offset = time::OffsetDateTime::now_utc();
+ let offset_time = {
+ let utc = time::OffsetDateTime::now_utc();
+ utc.checked_to_offset(*OFFSET).unwrap_or(utc)
+ };
out.finish(format_args!(
"{}[{}][{}] {}",
- offset
+ offset_time
.format(&time::macros::format_description!(
// The weird "[[[" is because we need to escape a bracket ("[[") to show one "[".
// See https://time-rs.github.io/book/api/format-description.html