fancy-log

Crates.iofancy-log
lib.rsfancy-log
version0.1.1
created_at2025-08-14 08:00:48.094305+00
updated_at2025-09-03 12:33:51.25051+00
descriptionA fancy logging library with colorized output and structured logs.
homepagehttps://github.com/canmi21/fancy-log
repositoryhttps://github.com/canmi21/fancy-log
max_upload_size
id1794595
size19,221
Canmi (canmi21)

documentation

https://docs.rs/fancy-log

README

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, and Debug log 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:SS format.
  • 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:

[dependencies]
fancy-log = "0.1.0"

Usage

Basic Example

use fancy_log::{log, set_log_level, LogLevel};

fn main() {
    // Set the minimum log level to Info
    set_log_level(LogLevel::Info);

    // Log messages
    log(LogLevel::Info, "This is an info message");
    log(LogLevel::Warn, "This is a warning message");
    log(LogLevel::Error, "This is an error message");
    log(LogLevel::Debug, "This debug message will not be shown");
}

Setting Log Level

You can configure the log level to filter out messages below a certain threshold:

use fancy_log::{set_log_level, LogLevel};

// Set log level to Debug to show all messages
set_log_level(LogLevel::Debug);

Log Output

  • Error: Printed to stderr in red.
  • Warn: Printed to stderr in yellow.
  • Info: Printed to stdout in white.
  • Debug: Printed to stdout in 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.

Commit count: 8

cargo fmt