2 releases
Uses new Rust 2024
| 0.1.1 | Sep 3, 2025 |
|---|---|
| 0.1.0 | Aug 14, 2025 |
#887 in Debugging
207 downloads per month
Used in 11 crates
7KB
63 lines
Fancy Log
A simple and customizable logging library for Rust, providing colored console output with timestamped log messages and configurable log levels.
Features
- Log Levels: Supports
Error,Warn,Info, andDebuglog levels. - Colored Output: Logs are displayed in different colors based on the log level (e.g., red for errors, yellow for warnings).
- Timestamps: Each log message includes a timestamp in
HH:MM:SSformat. - Thread-Safe: Uses a global, thread-safe log level configuration.
- Customizable: Easily set the minimum log level to filter messages.
Installation
Add the following to your Cargo.toml:
[dependencies]
fancy-log = "0.1.0"
Usage
Basic Example
use fancy_log::{log, set_log_level, LogLevel};
fn main() {
// Set the minimum log level to Info
set_log_level(LogLevel::Info);
// Log messages
log(LogLevel::Info, "This is an info message");
log(LogLevel::Warn, "This is a warning message");
log(LogLevel::Error, "This is an error message");
log(LogLevel::Debug, "This debug message will not be shown");
}
Setting Log Level
You can configure the log level to filter out messages below a certain threshold:
use fancy_log::{set_log_level, LogLevel};
// Set log level to Debug to show all messages
set_log_level(LogLevel::Debug);
Log Output
- Error: Printed to
stderrin red. - Warn: Printed to
stderrin yellow. - Info: Printed to
stdoutin white. - Debug: Printed to
stdoutin blue.
Example output:
12:34:56 This is an info message
12:34:56 This is a warning message
12:34:56 This is an error message
Dependencies
chrono = "0.4": For timestamp formatting.once_cell = "1.21": For thread-safe global log level storage.termcolor = "1.4.1": For colored console output.serde = { version = "1", features = ["derive"] }: For log level deserialization.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Dependencies
~1.3–4MB
~75K SLoC