# 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`:
```toml
[dependencies]
custom_logger = { git = "https://github.com/Shourya742/logger.git" }
```
---
## Example Usage
### Setup
To initialize the logger:
```rust
use custom_logger::{init_logger, info, error, trace};
use sinks::console::ConsoleSink;
use std::str::FromStr;
fn main() {
// Initialize logger with file and console output
init_logger(log_level::LogLevel::Trace, Box::new(ConsoleSink));
trace!("This is a trace log.");
info!("This is an info log.");
error!("This is an error log.");
}
```
### Output Example
```plaintext
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:
```rust
info!(user_id = 42, action = "login", "User action recorded");
debug!(config = ?config, status = "loading", "Loading configuration");
```
---
## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.