Crates.io | chromalog |
lib.rs | chromalog |
version | 0.0.2 |
source | src |
created_at | 2024-10-11 21:11:18.148915 |
updated_at | 2024-10-11 22:03:16.545392 |
description | A customizable logger with dynamic color coding and file logging. |
homepage | |
repository | |
max_upload_size | |
id | 1405849 |
size | 21,777 |
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
.
ERROR
, WARN
, INFO
, DEBUG
, and TRACE
.log
crate's interface.Add the following to your Cargo.toml
:
[dependencies]
chromalog = "0.1.0"
log = "0.4"
colored = "2.0"
chrono = "0.4"
## Example Usage
use chromalog::{ChromaLog, ColorConfig, ArgColor, error, warn, info, debug, trace, Color, LevelFilter};
use std::fs::File;
use std::sync::{Arc, Mutex};
fn main() {
// Create a log file (optional)
let log_file = File::create("my_log.log").expect("Unable to create log file");
let log_file = Arc::new(Mutex::new(log_file));
// Define custom colors for log levels
let custom_colors = ColorConfig {
error_color: Color::Red,
warn_color: Color::BrightYellow,
info_color: Color::BrightGreen,
debug_color: Color::BrightBlue,
trace_color: Color::BrightMagenta,
arg_color: None, // ArgColor::Fixed(Color::BrightMagenta), ArgColor::LogLevel
target_color: Color::Cyan,
datetime_color: None, // Use default color for datetime
};
// Initialize the logger with a custom color scheme and log file
ChromaLog::init(LevelFilter::Trace, custom_colors, Some(log_file)).unwrap();
// Log messages at different levels
error!("This is an error message.");
warn!("This is a warning message.");
info!("This is an info message.");
debug!("This is a debug message.");
trace!("This is a trace message.");
}