micrologger2

Crates.iomicrologger2
lib.rsmicrologger2
version0.1.0
created_at2025-12-06 20:46:48.9079+00
updated_at2025-12-06 20:46:48.9079+00
descriptionA minimal logger that prints colored output based on severity level
homepage
repositoryhttps://github.com/userx007/uRustMicroLogger
max_upload_size
id1970740
size11,171
V.M.P (userx007)

documentation

README

uRustMicroLogger

A minimal logger that prints colored output based on severity level.

Features

  • Colored output: Each log level has a distinctive color for easy visual identification
  • Multiple log levels: ERROR, WARN, INFO, DEBUG, VERBOSE, and TRACE
  • Flexible formatting: Works like println! macro - accepts format strings and arguments
  • Configurable coloring: Choose between coloring just the label or the entire line
  • Zero dependencies: Uses only standard ANSI color codes
  • Lightweight: Simple and fast with minimal overhead

Log Levels and Colors

Level Color Usage
ERROR Red Critical errors that need immediate attention
WARN Yellow Warning messages for potential issues
INFO Green General informational messages
DEBUG Blue Debug information for development
VERBOSE Cyan Detailed verbose output
TRACE Gray Fine-grained trace information

Usage

Add to your Cargo.toml:

[dependencies]
micrologger2 = "0.1.0"

Basic Usage

use micrologger::*;

fn main() {
    log_info!("Application started");
    log_error!("Failed to connect to server");
    log_warn!("Low memory warning");
}

With Format Arguments

use micrologger2::*;

fn main() {
    let user = "Alice";
    let count = 42;
    
    log_info!("User {} logged in", user);
    log_debug!("Processing {} items", count);
    log_error!("Connection failed after {} attempts", 3);
}

Using Specific Log Levels

use micrologger2::*;

fn main() {
    // Using convenience macros
    log_error!("Critical error!");
    log_warn!("Warning message");
    log_info!("Info message");
    log_debug!("Debug message");
    log_verbose!("Verbose output");
    log_trace!("Trace details");
    
    // Using the generic log macro
    log!(LogLevel::Info, "Custom log with level: {}", 123);
}

Configuring Color Mode

You can choose to color either just the log level label (default) or the entire line:

use micrologger2::*;

fn main() {
    // Default: only the label is colored
    log_info!("Only the [INFO] label is green");
    
    // Color the entire line
    set_color_entire_line(true);
    log_info!("This entire line is green");
    
    // Switch back to label-only coloring
    set_color_entire_line(false);
    log_info!("Back to label-only coloring");
}

Testing

You can test the logger locally by running the included example:

cargo run --example logtest

This will demonstrate all log levels and both coloring modes.

API Reference

Macros

  • log!(level, format, args...) - Generic logging macro with explicit level
  • log_error!(format, args...) - Log an error message (red)
  • log_warn!(format, args...) - Log a warning message (yellow)
  • log_info!(format, args...) - Log an info message (green)
  • log_debug!(format, args...) - Log a debug message (blue)
  • log_verbose!(format, args...) - Log a verbose message (cyan)
  • log_trace!(format, args...) - Log a trace message (gray)

Functions

  • set_color_entire_line(enabled: bool) - Configure whether to color the entire line or just the label
  • is_color_entire_line() -> bool - Check current color mode setting

Types

  • LogLevel - Enum representing log severity levels: Error, Warn, Info, Debug, Verbose, Trace

License

MIT

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Repository

https://github.com/userx007/uRustMicroLogger

Commit count: 0

cargo fmt