Skip to main content

init_logging

Function init_logging 

Source
pub fn init_logging(config: LoggingConfig) -> Result<(), LoggingError>
Expand description

Initialize the logging system with the given configuration

This function sets up the tracing subscriber with the specified configuration. It can only be called once - subsequent calls will return LoggingError::AlreadyInitialized.

§Per-Module Log Levels

The logging system respects the RUST_LOG environment variable for per-module log level configuration. If RUST_LOG is set, it takes precedence over the config.level parameter for fine-grained control.

The config.level serves as the default/fallback level when RUST_LOG is not set.

§Arguments

  • config - Logging configuration specifying level, format, and output

§Returns

  • Ok(()) - Logging initialized successfully
  • Err(LoggingError) - Initialization failed

§Example

use elara_runtime::observability::logging::{LoggingConfig, LogLevel, LogFormat, LogOutput, init_logging};

let config = LoggingConfig {
    level: LogLevel::Info,
    format: LogFormat::Json,
    output: LogOutput::Stdout,
};

init_logging(config).expect("Failed to initialize logging");

§Idempotency

This function is idempotent in the sense that calling it multiple times will not reinitialize the logging system. The second and subsequent calls will return Err(LoggingError::AlreadyInitialized).