Crate lumelog

Crate lumelog 

Source
Expand description

§LumeLog - A Flexible Rust Logging Library

LumeLog provides a lightweight, thread-safe, and configurable logging system with support for different log levels, styled console output, and file logging in multiple formats.

§Features

  • Adjustable log levels: ERROR, WARN, INFO, DEBUG, TRACE with proper ordering
  • Styled console output: Color-coded log levels for enhanced readability
  • File logging: Directory-based logging with automatic directory creation
  • Multiple formats: JSON and plain text file output formats
  • Thread-safe: Uses OnceCell for safe global configuration management
  • Runtime configuration: Configure without recompilation
  • Performance: Zero-cost abstractions when logging is disabled

§Quick Start

use lumelog::{ConfigBuilder, LogLevel, info, warn, error};
 
// Initialize logging configuration (call once at startup)
ConfigBuilder::new()
    .log_level(Some(LogLevel::INFO))
    .build()
    .expect("Failed to initialize logging");
 
// Use logging macros throughout your application
info!("Application started successfully");
warn!("This is a warning message");
error!("An error occurred: {}", "connection timeout");

§File Logging Example

use lumelog::{ConfigBuilder, FileLoggerBuilder, FileLoggerFormat};
 
let mut file_logger = FileLoggerBuilder::new();
file_logger.enabled = true;
file_logger = file_logger
    .dir_path(Some("app_logs".to_string()))
    .log_format(FileLoggerFormat::JSON);
 
ConfigBuilder::new()
    .file_logger_config(Some(file_logger))
    .build()
    .expect("Failed to initialize file logging");

§Architecture

LumeLog uses a singleton pattern with OnceCell to ensure thread-safe, single initialization of the global configuration. This design provides:

  • Thread safety: Multiple threads can log safely without locks during runtime
  • Performance: Minimal overhead after initialization
  • Consistency: Single configuration across the entire application

Macros§

debug
Logs a debug message at DEBUG level.
error
Logs an error message at ERROR level with optional context information.
info
Logs an informational message at INFO level.
trace
Logs a trace message at TRACE level with automatic context information.
warn
Logs a warning message at WARN level.

Structs§

Config
Internal immutable logging configuration.
ConfigBuilder
Builder pattern for configuring the global logging system.
FileLogger
Internal configuration for file-based logging operations.
FileLoggerBuilder
Builder pattern for configuring file-based logging.

Enums§

FileLoggerCleanUpPolicy
Represents the automatic cleanup policy for log files.
FileLoggerFormat
Represents the output format for file-based logging.
LogLevel
Represents the severity level of logs with hierarchical ordering.