| Crates.io | lumelog |
| lib.rs | lumelog |
| version | 0.1.9 |
| created_at | 2024-12-07 19:04:46.344537+00 |
| updated_at | 2025-10-19 00:02:08.761207+00 |
| description | A lightweight, flexible, and configurable logging library for Rust, with support for runtime configuration and build-mode detection. |
| homepage | |
| repository | https://github.com/LinearDev/lumelog |
| max_upload_size | |
| id | 1475820 |
| size | 169,131 |
LumeLog is a lightweight, flexible, and configurable logging library for Rust. It supports different log levels, runtime configuration, and styled log outputs, making it suitable for both development and production environments.
Key Highlights:
ERROR, WARN, INFO, DEBUG, and TRACE.Add lumelog to your Cargo.toml:
[dependencies]
lumelog = "0.1.6"
Then, include it in your code:
use lumelog::{info, warn, error, ConfigBuilder, LogLevel};
Hereβs a basic example to get started:
use lumelog::{info, error, warn, debug, ConfigBuilder, LogLevel};
fn main() {
// Configure LumeLog
let config = ConfigBuilder::new().build().unwrap();
// Example log messages
info!("This is an informational message");
warn!("This is a warning!");
error!("This is an error!");
//Example with variables
let test_var = "some data to test"
debug!("This is debug variable value: {}", test_var)
}
You can customize LumeLog using the ConfigBuilder. Hereβs what you can configure:
Example:
let config = ConfigBuilder::new()
.log_level(Some(LogLevel::DEBUG)) // Log all messages down to DEBUG
.build()
.unwrap();
Enable file logging with automatic directory creation and specify format:
use lumelog::{FileLoggerBuilder, FileLoggerFormat};
let mut file_logger = FileLoggerBuilder::new();
file_logger.enabled = true; // Enable file logging
file_logger = file_logger
.dir_path(Some("logs".to_string())) // Specify directory (creates if needed)
.log_format(FileLoggerFormat::JSON); // Set file format to JSON
let config = ConfigBuilder::new()
.file_logger_config(Some(file_logger))
.build()
.unwrap();
// Nested directory creation (automatically created)
let file_logger = FileLoggerBuilder::new()
.dir_path(Some("app/logs/2024".to_string()))
.log_format(FileLoggerFormat::TEXT);
// Default directory (uses "logs" if not specified)
let file_logger = FileLoggerBuilder::new()
.dir_path(None) // Defaults to "logs" directory
.log_format(FileLoggerFormat::JSON);
LumeLog provides easy-to-use macros for logging messages at various levels:
Example:
info!("User {} has logged in", "Alice");
warn!("Memory usage is high: {}%", 90);
error!("Failed to save data: {}", "Disk full");
let mut file_logger = FileLoggerBuilder::new();
file_logger.enabled = true; // Enable file logging
file_logger = file_logger
.dir_path(Some("app_logs".to_string())) // Directory for log files
.log_format(FileLoggerFormat::TEXT); // Format of the log files
ConfigBuilder{
log_level: Some(lumelog::LogLevel::INFO), // Log level for the logger.
log_in_release: true, // Enables or disables logging in release mode.
log_with_time: Some(true), // Enables or disables time-stamping in logs.
std: true, // Enables or disables standard output logging.
file_logger_config: Some(file_logger), // Configuration for file-based logging.
}
LumeLog automatically detects build mode (debug or release) and adjusts logging behavior accordingly. You can override this behavior using the log_in_release configuration.
!NOTE: If log_in_release is enabled, trace and debug messages will not be logged.
LumeLog is designed with performance and flexibility in mind:
LogLevel: Enum defining log severity levels with proper orderingConfig: Global configuration managed by OnceCell for thread-safe single initializationFileLogger: Configurable file output with multiple format support// Text format (default) - logs/app_20241019.log
2023-10-18 14:30:25 INFO User login successful
// JSON format - logs/app_20241019.json
{"timestamp":"2023-10-18T14:30:25Z","level":"INFO","message":"User login successful"}
logs/app/2024/october)LumeLog provides beautifully styled console output:
ERROR Critical system failure detected
WARN High memory usage: 89%
INFO Application started successfully
DEBUG Processing user request: /api/users
TRACE Database query executed in 12ms
Each level has its own distinct color scheme for quick visual identification.
Q: Tests fail with "OnceCell already initialized" error
# Solution: Run tests sequentially
make test
# OR
cargo test --test main -- --test-threads=1
Q: Logs not appearing in release mode
// Solution: Enable release logging
ConfigBuilder::new()
.log_in_release(true) // Enable this flag
.build()
.unwrap();
Q: File logging not working
// Solution: Ensure file logger is enabled and directory is specified
let mut file_logger = FileLoggerBuilder::new();
file_logger.enabled = true; // Don't forget this!
file_logger = file_logger.dir_path(Some("logs".to_string()));
Q: Configuration can't be changed after first setup
This is expected behavior! LumeLog uses OnceCell for thread-safe
single initialization. The configuration is global and immutable
after the first call to .build().
LumeLog comes with a comprehensive test suite that ensures reliability and correctness across all features.
The project includes 40+ integration tests organized across multiple test files:
tests/main.rs - Core API Tests (21 tests)tests/file_logging.rs - File Logging Tests (10 tests)tests/file_logging_advanced.rs - Advanced Tests (9 tests)logs/nested/deep/directory)Run tests using the Makefile:
make test # Run all 40+ tests (sequential for OnceCell safety)
make test-verbose # Run tests with detailed output
make test-integration # Run integration tests only
make test-coverage # Generate coverage report (requires cargo-tarpaulin)
Or use cargo directly:
# Run all tests
cargo test -- --test-threads=1
# Run specific test files
cargo test --test main -- --test-threads=1 # Core API tests
cargo test --test file_logging -- --test-threads=1 # File logging tests
cargo test --test file_logging_advanced -- --test-threads=1 # Advanced file tests
Note: Tests are run with
--test-threads=1to ensure proper OnceCell behavior testing, as the global CONFIG can only be initialized once per process.
tests/
βββ main.rs # Core API and configuration tests (21 tests)
βββ file_logging.rs # Basic file logging functionality (10 tests)
βββ file_logging_advanced.rs # Advanced scenarios and edge cases (9 tests)
βββ README.md # Test documentation and usage guide
Each test file is self-contained with proper setup, execution, and cleanup phases.
This project includes a comprehensive Makefile with useful development commands:
make help # Show all available commands
make build # Build in debug mode
make build-release # Build in release mode
make test # Run tests
make fmt # Format code
make clippy # Run linter
make clean # Clean build artifacts
make pre-commit # Run all pre-commit checks (format, lint, test)
make ci-check # Run CI pipeline checks
make release-check # Full release validation
make doc # Generate documentation
make doc-open # Generate and open docs in browser
make deps # Install development dependencies
make update # Update dependencies
make audit # Security audit
make info # Show project information
dir_path for automatic directory creationmain.rs, file_logging.rs, file_logging_advanced.rs)dir_pathlogs/app/2024/octobergit checkout -b feature/amazing-feature)make pre-commitgit commit -m 'Add amazing feature')git push origin feature/amazing-feature)| Metric | Value |
|---|---|
| Lines of Code | ~800+ |
| Test Coverage | 40+ integration tests across 3 files |
| Makefile Commands | 30+ development commands |
| Dependencies | 3 (minimal footprint) |
| Rust Edition | 2021 |
| MSRV | 1.56+ |
| Test Categories | Core API (21) + File Logging (19) |
chrono, colored, once_cellIf LumeLog helps your project, consider giving it a β on GitHub!
Made with π¦ and β by LinearDev
LumeLog is dual-licensed under the MIT or Apache 2.0 license. See LICENSE-MIT or LICENSE-APACHE for details.