ChromaLog
ChromaLog is a customizable, colorful logger for Rust applications. It enables dynamic color coding of log levels and supports writing log messages to both the console and an optional log file. You can define your own color scheme for different log levels, including ERROR, WARN, INFO, DEBUG, and TRACE.
Features
- Customizable Color Scheme: Define colors for log levels and other components such as the log target or timestamp.
- File Logging: Optionally write log messages to a specified log file while still printing them to the console.
- Supports All Log Levels:
ERROR,WARN,INFO,DEBUG, andTRACE. - Timestamped Logs: Logs include date and time with millisecond precision.
- Console and File Output: Log messages are simultaneously printed to the console and can be saved to a log file.
- Simple Integration: Easily add it to your project using the
logcrate's interface.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0"
= "0.4"
= "2.0"
= "0.4"
## Example Usage
{ChromaLog, ColorConfig};
{error, warn, info, debug, trace, LevelFilter};
fs::File;
sync::{Arc, Mutex};
{
// Create a log file (optional)
= File::create("my_log.log").expect("Unable to create log file");
= Arc::new(Mutex::new(log_file));
// Define custom colors for log levels
= ColorConfig {
Color::Red,
Color::BrightYellow,
Color::BrightGreen,
Color::BrightBlue,
Color::BrightMagenta,
Color::Cyan,
None, // Use default color for datetime
};
// Initialize the logger with a custom color scheme and log file
init(LevelFilter::Trace, custom_colors, Some(log_file)).unwrap();
// Log messages at different levels
"This is an error message.");
"This is a warning message.");
"This is an info message.");
"This is a debug message.");
"This is a trace message.");
}