Custom Logger
A lightweight, structured logger built from scratch with support for multiple output backends and configurable logging levels. Designed to log efficiently to the console, files, and other backends while maintaining a focus on structured logging with key-value pairs.
Features
- Multiple Outputs: Supports logging to the console and files.
- Configurable Levels: Easily set logging levels (e.g., trace, debug, info, warn, error).
- Structured Logging: Accepts key-value pairs for clear and structured logs.
- Minimal Dependencies: Only depends on the
chrono
crate for timestamps. - Expandable: Additional logging backends can be added as needed.
Installation
Add this crate to your Cargo.toml
:
[]
= { = "https://github.com/Shourya742/logger.git" }
Example Usage
Setup
To initialize the logger:
use ;
use ConsoleSink;
use FromStr;
Output Example
2025-01-10T16:35:37.689459275+00:00 TRACE logger::test - This is a trace log.
2025-01-10T16:35:37.689475106+00:00 INFO logger::test - This is an info log.
2025-01-10T16:35:37.689478106+00:00 ERROR logger::test - This is an error log.
Structured Logging
You can pass key-value pairs directly for structured logs:
info!;
debug!;
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.