summaryrefslogtreecommitdiffstats
path: root/src/utils/logging.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/logging.rs')
-rw-r--r--src/utils/logging.rs44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/utils/logging.rs b/src/utils/logging.rs
index 0b56591c..00e7e3db 100644
--- a/src/utils/logging.rs
+++ b/src/utils/logging.rs
@@ -1,22 +1,8 @@
#[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
- }
-});
+use std::sync::OnceLock;
+
+#[cfg(feature = "logging")]
+pub static OFFSET: OnceLock<time::UtcOffset> = OnceLock::new();
#[cfg(feature = "logging")]
pub fn init_logger(
@@ -24,9 +10,29 @@ pub fn init_logger(
) -> Result<(), fern::InitError> {
let dispatch = fern::Dispatch::new()
.format(|out, message, record| {
+ let offset = OFFSET.get_or_init(|| {
+ 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
+ }
+ });
+
let offset_time = {
let utc = time::OffsetDateTime::now_utc();
- utc.checked_to_offset(*OFFSET).unwrap_or(utc)
+ utc.checked_to_offset(*offset).unwrap_or(utc)
};
out.finish(format_args!(