Module log

Module log 

Source
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.0

Unless 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

  1. Multiple Outputs: Supports both console and file logging
  2. Structured Logging: Supports both text and JSON formats
  3. Distributed Tracing: Integrates with distributed tracing context
  4. Configurable: Highly configurable through DMSCLogConfig
  5. Performance: Includes sampling support for high-volume logging
  6. Log Rotation: Supports size-based log rotation
  7. 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§

DMSCLogConfig
Public logging configuration class.
DMSCLogContext
Log context for DMSC, similar to MDC with distributed tracing support.
DMSCLogger
Public-facing logger class.

Enums§

DMSCLogLevel
Log level definition.