| Crates.io | lazylog |
| lib.rs | lazylog |
| version | 0.1.4 |
| created_at | 2026-01-14 08:58:35.440291+00 |
| updated_at | 2026-01-14 08:58:35.440291+00 |
| description | A flexible logging library with file rotation and structured output |
| homepage | |
| repository | https://github.com/lazywalker/lazylog |
| max_upload_size | |
| id | 2042446 |
| size | 139,814 |
A flexible logging library with file rotation and structured output for Rust applications.
tracing ecosystemAdd this to your Cargo.toml:
[dependencies]
lazylog = "0.1"
Optional features:
file: Enable file logging supportansi: Enable ANSI color codes in console outputtime: Enable time-based log rotationuse lazylog;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize logging
lazylog::builder()
.with_console(true)
.with_level("info")
.init()?;
tracing::info!("Application started");
Ok(())
}
// Console logging
lazylog::builder()
.with_console(true)
.with_level("debug")
.init()?;
// File logging with size rotation
lazylog::builder()
.with_file("app.log")
.with_rotation(lazylog::RotationTrigger::size(1024 * 1024, 5)) // 1MB, keep 5 files
.init()?;
// JSON format
lazylog::builder()
.with_console(true)
.with_format("json")
.init()?;
use lazylog::{RotationTrigger, RotationPeriod};
// Size-based rotation
RotationTrigger::size(10 * 1024 * 1024, 5) // 10MB, keep 5 files
// Time-based rotation (requires `time` feature)
RotationTrigger::time(RotationPeriod::Daily)
// Hybrid rotation
RotationTrigger::both(RotationPeriod::Daily, 10 * 1024 * 1024, 5)
log:
console: true
level: info
format: text
file:
path: /var/log/app.log
rotation:
size: 10M
lazylog::builder() - Create a new builderwith_console(bool) - Enable console loggingwith_level(&str) - Set log levelwith_format(&str) - Set format ("text" or "json")with_file(path) - Enable file loggingwith_rotation(RotationTrigger) - Set rotationinit() - Initialize loggingsize(max_size: u64, max_files: usize) - Size-based rotationtime(period: RotationPeriod) - Time-based rotationboth(period, max_size, max_files) - Hybrid rotationHourly, Daily, Weekly, Monthlycargo test
Contributions are welcome! Please feel free to submit a Pull Request.