Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtime] Enhancement: add a custom logging initializer #1504

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/rust/runtime/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
// Imports
//======================================================================================================================

use ::flexi_logger::{with_thread, Logger};
use ::std::sync::Once;
use ::flexi_logger::{with_thread, Logger, LoggerHandle};
use ::std::sync::OnceLock;

//======================================================================================================================
// Static Variables
//======================================================================================================================

/// Guardian to the logging initialize function.
static INIT_LOG: Once = Once::new();
static LOG_HANDLE: OnceLock<LoggerHandle> = OnceLock::new();

//======================================================================================================================
// Standalone Functions
//======================================================================================================================

/// Initializes logging features.
pub fn initialize() {
INIT_LOG.call_once(|| {
Logger::try_with_env().unwrap().format(with_thread).start().unwrap();
let _ = LOG_HANDLE.get_or_init(|| Logger::try_with_env().unwrap().format(with_thread).start().unwrap());
}

/// Initialize logging features. The given callback function will initialize FlexiLogger (using a
/// `flexi_logger::Logger` constructor) as desired by the consumer, returning the Logger instance
/// which is then started by Demikernel.
#[allow(unused)]
pub fn custom_initialize<F: FnOnce() -> Logger>(f: F) {
let _ = LOG_HANDLE.get_or_init(|| {
let logger: Logger = f();
logger.start().unwrap()
});
}