chromalog 0.0.2

A customizable logger with dynamic color coding and file logging.
Documentation
  • Coverage
  • 0%
    0 out of 16 items documented0 out of 4 items with examples
  • Size
  • Source code size: 31.44 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.66 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • burnmandont

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, and TRACE.
  • 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 log crate's interface.

Installation

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.");
}