From 3d8b24048b6be436412f0e9b1eb32fc79db19332 Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Thu, 10 Sep 2026 08:45:06 +0200 Subject: [PATCH] expose `logging::is_initialized` --- src/logging.rs | 13 +++++++++++-- tests/logging_not_initialized.rs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/logging.rs b/src/logging.rs index e0fc1f83..3de79271 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -228,6 +228,13 @@ impl fmt::Display for LogStorage { } } +/// Whether Rustwide's logging system has been initialized. +/// +/// Call `init` or `init_with` before capturing logs. +pub fn is_initialized() -> bool { + INITIALIZED.load(Ordering::SeqCst) +} + /// Capture all log messages emitted inside a closure. /// /// This function will capture all the message the provided closure emitted **in the current @@ -254,8 +261,10 @@ impl fmt::Display for LogStorage { /// [`init`]: fn.init.html /// [`init_with`]: fn.init_with.html pub fn capture(storage: &LogStorage, f: impl FnOnce() -> R) -> R { - if !INITIALIZED.load(Ordering::SeqCst) { - panic!("called capture without initializing rustwide::logging"); + if !is_initialized() { + panic!( + "Rustwide logging is not initialized; call rustwide::logging::init() or init_with() before capture()" + ); } let storage = Box::new(storage.clone()); diff --git a/tests/logging_not_initialized.rs b/tests/logging_not_initialized.rs index 57aecc57..af907b0c 100644 --- a/tests/logging_not_initialized.rs +++ b/tests/logging_not_initialized.rs @@ -2,7 +2,7 @@ use log::{LevelFilter, info}; use rustwide::logging::{self, LogStorage}; #[test] -#[should_panic = "called capture without initializing rustwide::logging"] +#[should_panic = "Rustwide logging is not initialized; call rustwide::logging::init() or init_with() before capture()"] fn test_not_initialized() { let storage = LogStorage::new(LevelFilter::Info); logging::capture(&storage, || {