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:
[]
= "0.1.0"
Usage
Basic Example
use ;
Setting Log Level
You can configure the log level to filter out messages below a certain threshold:
use ;
// Set log level to Debug to show all messages
set_log_level;
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.