zlogger.rs
A lightweight, configurable Rust logging library with color support and file rotation.
Features
- ð Color-coded log levels for terminal output
- ð§ Environment variable configuration
- ð File logging with automatic rotation
- ðŊ Multiple output targets (console, file, or both)
- ⥠Thread-safe logging
- ðŠķ Minimal dependencies
Quick Start
Add this to your Cargo.toml:
[]
= "0.0.1"
Basic usage:
use ;
Configuration
Environment Variables
| Variable | Description | Default | Example |
|---|---|---|---|
ZLOG_LEVEL |
Minimum log level | info |
debug |
ZLOG_OUTPUT |
Output target | console |
file, both |
ZLOG_FILE |
Log file path | app.log |
/var/log/myapp.log |
ZLOG_MAX_SIZE |
Max file size (bytes) | 10485760 (10MB) |
1048576 (1MB) |
ZLOG_MAX_FILES |
Max rotated files | 5 |
10 |
ZLOG_COLOR |
Enable colors | true |
false |
Programmatic Configuration
use ;
let config = default
.level
.output
.file_path
.max_file_size // 5MB
.max_files
.use_colors;
init_with_config;
Log Levels
trace- Very detailed debug informationdebug- Debug informationinfo- General informationwarn- Warning messageserror- Error messages
File Rotation
When a log file reaches the maximum size, it's automatically rotated:
app.logâapp.log.1app.log.1âapp.log.2- etc.
Old files beyond the maximum count are automatically deleted.
Examples
Run the basic example:
License
Licensed under MIT license.
Credits
- @liuzhen9320 - Project author
- All contributors to the
rust-langecosystem who have made this project possible
Built with âĪïļ in Rust for the community