18 releases
0.1.17 | Jan 4, 2025 |
---|---|
0.1.16 | Jan 4, 2025 |
#326 in Debugging
890 downloads per month
31KB
719 lines
Rich Logger
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.
Dependencies
~4–13MB
~180K SLoC