| Crates.io | daily-logger |
| lib.rs | daily-logger |
| version | 0.1.1 |
| created_at | 2025-08-16 23:37:58.628787+00 |
| updated_at | 2025-08-19 20:28:15.437426+00 |
| description | A Rust logging library that provides daily file rotation and colored console output with support for order-specific logging. |
| homepage | |
| repository | https://github.com/xukangmin/daily-logger |
| max_upload_size | |
| id | 1798993 |
| size | 33,993 |
A Rust logging library that provides daily file rotation and colored console output with support for order-specific logging.
Add this to your Cargo.toml:
[dependencies]
daily-logger = "0.1.0"
use daily_logger::init_logger;
use log::{info, warn, error, debug, trace};
fn main() {
// Initialize logger with console level, file level, and base path
init_logger(
log::LevelFilter::Info, // Console output level
log::LevelFilter::Debug, // File output level
"/path/to/logs" // Base directory for log files
);
// Use standard log macros
info!("Application started");
warn!("This is a warning");
error!("An error occurred");
}
The logger supports special UUID-based logging for tracking specific orders or transactions:
use log::info;
fn main() {
daily_logger::init_logger(
log::LevelFilter::Info,
log::LevelFilter::Info,
"/var/logs"
);
let order_id = "123e4567-e89b-12d3-a456-426614174000";
// This will create a separate log file: order_123e4567-e89b-12d3-a456-426614174000.log
info!(target: "orders", uuid = order_id; "Order processing started");
info!(target: "orders", uuid = order_id; "Payment validated");
info!(target: "orders", uuid = order_id; "Order completed");
}
Console logs are colored by level and include timestamps:
2024-01-15T10:30:45+00:00-INFO|[orders]<123e4567>:Order processing started
Files are created in the base directory:
log_2024_1_15.log (contains all logs for the day)order_123e4567-e89b-12d3-a456-426614174000.log (UUID-specific logs)The library supports standard log levels with color coding:
| Level | Color | Description |
|---|---|---|
| ERROR | Red | Error conditions |
| WARN | Yellow | Warning conditions |
| INFO | Green | Informational messages |
| DEBUG | Blue | Debug information |
| TRACE | Gray | Trace information |
You can set different log levels for console and file output:
daily_logger::init_logger(
log::LevelFilter::Warn, // Only warnings and errors to console
log::LevelFilter::Trace, // All levels to files
"/var/logs"
);
The logger uses an internal file cache (max 32 files) with LRU eviction to efficiently manage file handles. Log directories are created automatically if they don't exist.
chrono - Date and time handlinglog - Logging facadeonce_cell - Thread-safe lazy initializationdashmap - Concurrent hash map (if used in your implementation)This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.