log4rc
A log4j-like logging framework for Rust.
Overview
log4rc is a simple, extensible logging framework inspired by log4j. It provides different log levels and an easy-to-use API for Rust applications.
Features
- Multiple log levels (Trace, Debug, Info, Warn, Error)
- Simple API similar to log4j
- Thread-safe logging
- Timestamped log entries
- Configurable log levels
- File appender (append logs to disk)
- Cheap to disable: filtered-out levels skip formatting entirely
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Example
use ;
Custom appenders
log4rc is extensible: implement the Appender trait (output target) and the Layout trait (message formatting), then build a logger with Logger::builder.
use ;
;
You can add multiple appenders, and Logger::init remains a shortcut that installs a console appender with the default layout.
File appender
FileAppender appends formatted events to a file (creating it if needed) and flushes after every event. Size-based rotation is available via the builder — once the file reaches the limit, it is rolled over to a timestamped sibling (e.g. app.log.20260809-102530-1). max_files bounds how many rotated files are kept (the oldest are deleted once the count is exceeded), and .compressed() gzips rotated files:
use ;
builder
.appender
.appender
.init;
License
This project is licensed under the MIT License - see the LICENSE file for details.