Expand description
Structured logging with tracing integration Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of DMSC. The DMSC 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 DMSC, supporting multiple output formats, log levels, and configurable logging behavior. It includes support for structured logging, distributed tracing integration, and log rotation.
§Key Components
- DMSCLogLevel: Enum defining supported log levels (Debug, Info, Warn, Error)
- DMSCLogConfig: Configuration struct for logging behavior
- DMSCLogContext: Thread-local context for adding contextual information to logs
- DMSCLogger: 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
DMSCLogConfig - 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 dmsc::prelude::*;
fn example() -> DMSCResult<()> {
// Create a default log configuration
let log_config = DMSCLogConfig::default();
// Create a file system instance (usually provided by the service context)
let fs = DMSCFileSystem::new();
// Create a logger
let logger = DMSCLogger::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§
- DMSC
LogConfig - Public logging configuration class.
- DMSC
LogContext - Log context for DMSC, similar to MDC with distributed tracing support.
- DMSC
Logger - Public-facing logger class.
Enums§
- DMSC
LogLevel - Log level definition.