| Crates.io | custom_logger |
| lib.rs | custom_logger |
| version | 0.1.0 |
| created_at | 2025-01-10 16:48:08.352468+00 |
| updated_at | 2025-01-10 16:48:08.352468+00 |
| description | A lightweight logger crate for structured and configurable logging to console and file. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1511472 |
| size | 16,234 |
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.
chrono crate for timestamps.Add this crate to your Cargo.toml:
[dependencies]
custom_logger = { git = "https://github.com/Shourya742/logger.git" }
To initialize the logger:
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.");
}
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.
You can pass key-value pairs directly for structured logs:
info!(user_id = 42, action = "login", "User action recorded");
debug!(config = ?config, status = "loading", "Loading configuration");
Contributions are welcome! Feel free to open issues or submit pull requests.