Expand description
Structured logging system for ELARA Protocol
This module provides structured, queryable logging with support for:
- Multiple log levels (Trace, Debug, Info, Warn, Error)
- Multiple output formats (JSON, Pretty, Compact)
- Multiple output destinations (Stdout, Stderr, File)
- Per-module log level configuration via RUST_LOG environment variable
- Contextual fields (node_id, session_id, peer_id) in all log entries
§Per-Module Log Levels
You can configure different log levels for different modules using the RUST_LOG
environment variable. This is useful for debugging specific components without
overwhelming logs from other parts of the system.
§Examples
# Set all modules to info, but elara_wire to debug
RUST_LOG=info,elara_wire=debug
# Set elara_crypto to trace, everything else to warn
RUST_LOG=warn,elara_crypto=trace
# Multiple module overrides
RUST_LOG=info,elara_wire=debug,elara_state=trace,elara_transport=warn§Contextual Fields
The logging system supports attaching contextual fields to log entries. These fields provide additional context about the operation being logged:
node_id: Identifier of the node generating the logsession_id: Current session identifierpeer_id: Identifier of the peer involved in the operation
Use the tracing macros with field syntax to add contextual information:
use tracing::info;
info!(
node_id = "node-1",
session_id = "session-abc",
peer_id = "peer-xyz",
"Connection established"
);§Basic 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");Structs§
- Logging
Config - Configuration for the logging system
Enums§
- LogFormat
- Log output format
- LogLevel
- Log level enumeration
- LogOutput
- Log output destination
- Logging
Error - Errors that can occur during logging initialization
Functions§
- init_
logging - Initialize the logging system with the given configuration