Expand description
Structured logging with tracing integration Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of Ri. The Ri project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§Logging System
This module provides a comprehensive logging system for Ri, supporting multiple output formats, log levels, and configurable logging behavior. It includes support for structured logging, distributed tracing integration, and log rotation.
§Key Components
- RiLogLevel: Enum defining supported log levels (Debug, Info, Warn, Error)
- RiLogConfig: Configuration struct for logging behavior
- RiLogContext: Thread-local context for adding contextual information to logs
- RiLogger: Public-facing logger class for application use
- LoggerImpl: Internal logger implementation
§Design Principles
- Multiple Outputs: Supports both console and file logging
- Structured Logging: Supports both text and JSON formats
- Distributed Tracing: Integrates with distributed tracing context
- Configurable: Highly configurable through
RiLogConfig - Performance: Includes sampling support for high-volume logging
- Log Rotation: Supports size-based log rotation
- Contextual Logging: Allows adding contextual information to logs
§Usage
use ri::prelude::*;
fn example() -> RiResult<()> {
// Create a default log configuration
let log_config = RiLogConfig::default();
// Create a file system instance (usually provided by the service context)
let fs = RiFileSystem::new();
// Create a logger
let logger = RiLogger::new(&log_config, fs);
// Log messages at different levels
logger.debug("example", "Debug message")?;
logger.info("example", "Info message")?;
logger.warn("example", "Warning message")?;
logger.error("example", "Error message")?;
Ok(())
}Structs§
- RiLog
Config - Public logging configuration class.
- RiLog
Context - Log context for Ri, similar to MDC with distributed tracing support.
- RiLogger
- Public-facing logger class.
Enums§
- RiLog
Level - Log level definition.