rich-logger

Crates.iorich-logger
lib.rsrich-logger
version0.1.17
created_at2025-01-01 07:20:16.674783+00
updated_at2025-01-04 12:11:05.871814+00
descriptionRich logger implmentation in rust
homepage
repositoryhttps://github.com/eatmynerds/rich-logger
max_upload_size
id1500644
size32,730
Jason Spalti (eatmynerds)

documentation

README

Rich Logger

crates.io

Rich Logger is a beautiful and performant logging library for Rust, inspired by Python's rich package. It provides colorful and structured logging output, making it easier to debug and monitor applications.

Installation

To use Rich Logger in your project, add the rich-logger and log crates to your Cargo.toml:

$ cargo add log rich-logger

Or manually add the dependencies:

[dependencies]
log = "0.4"
rich-logger = "<latest-version>"

Usage

Basic Example

The following example demonstrates how to initialize Rich Logger and log a simple message:

use log::{info, LevelFilter};

fn main() {
    rich_logger::init(LevelFilter::Debug).expect("Failed to initialize logger!");
    info!("Hello, World!");
}

Asynchronous Logging

$ cargo add rich-logger -F async

Note: Ensures whole messages are written to the terminal even if called from multiple threads

JSON Logging

Log highlighted data in JSON format using the json feature:

use log::{info, LevelFilter};
use serde_json::json;

fn main() {
    rich_logger::init(LevelFilter::Debug).expect("Failed to initialize logger!");
    info!("{}", json!({"x": 10, "y": 20}));
}

Output example:

{"x": 10, "y": 20}

Note: If you want json output to be formatted and indented you'll want to enable the pretty_json feature


Contributing

Contributions are welcome! If you encounter issues or have ideas for new features, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Commit count: 57

cargo fmt