| Crates.io | logly |
| lib.rs | logly |
| version | 0.0.4 |
| created_at | 2024-01-09 15:19:43.468981+00 |
| updated_at | 2025-11-03 16:20:15.093769+00 |
| description | High-performance, structured logging library with async support, rotation, filtering, and GPU/CPU optimization |
| homepage | https://github.com/muhammad-fiaz/logly-rs |
| repository | https://github.com/muhammad-fiaz/logly-rs.git |
| max_upload_size | |
| id | 1094107 |
| size | 282,790 |
High-performance, production-ready structured logging library for Rust
logly-rs is a high-performance, production-ready structured logging library for Rust with async support, GPU acceleration, rotation, filtering, callbacks, and comprehensive error handling.
--features gpu)Add to your Cargo.toml:
[dependencies]
logly = "0.0.4"
# With GPU support (experimental)
logly = { version = "0.0.4", features = ["gpu"] }
use logly::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let logger = Logger::new();
logger.add_sink(SinkConfig::default())?;
logger.info("Application started".to_string())?;
logger.success("Operation completed!".to_string())?;
logger.warning("Warning message".to_string())?;
logger.error("Error occurred".to_string())?;
Ok(())
}
Real benchmark results from criterion (measured on your system):
| Operation | Average Time | Throughput | Notes |
|---|---|---|---|
| Basic INFO log | 75.6 μs | 13,200 ops/sec | Single message to console |
| File logging | ~150 μs | 6,600 ops/sec | With async write |
| With context | ~130 μs | 7,700 ops/sec | 2-3 bound fields |
| Concurrent (10 threads) | ~500 μs | 2,000 ops/sec | 10 threads × 100 messages |
| Multiple sinks (5) | ~200 μs | 5,000 ops/sec | Console + 4 files |
| TRACE level | ~74 μs | 13,500 ops/sec | Fastest level |
| DEBUG level | ~75 μs | 13,300 ops/sec | |
| INFO level | ~76 μs | 13,200 ops/sec | |
| WARNING level | ~75 μs | 13,300 ops/sec | |
| ERROR level | ~76 μs | 13,200 ops/sec |
Benchmarks run with criterion on Windows. Times include formatting, serialization, and I/O.
See Performance Guide for optimization techniques.
use logly::prelude::*;
use std::path::PathBuf;
let logger = Logger::new();
let config = SinkConfig {
path: Some(PathBuf::from("logs/app.log")),
rotation: Some("daily".to_string()),
size_limit: Some(10 * 1024 * 1024), // 10MB
retention: Some(7), // Keep 7 files
async_write: true,
..Default::default()
};
logger.add_sink(config)?;
// Add custom level with priority between WARNING (30) and ERROR (40)
logger.add_custom_level("NOTICE".to_string(), 35, "96".to_string())?;
// Use custom level
logger.log_custom("NOTICE", "Custom level message".to_string())?;
// Log callback for monitoring
logger.add_log_callback(|record| {
if record.level >= Level::Error {
println!("High severity: {}", record.message);
}
Ok(())
});
// Custom color callback
logger.add_color_callback(|level, message| {
format!("\x1b[1m[{}]\x1b[0m {}", level.as_str(), message)
});
// Exception callback
logger.add_exception_callback(|error, backtrace| {
eprintln!("Exception: {}\n{}", error, backtrace);
});
// Bind persistent context
logger.bind("user_id".to_string(), serde_json::json!("12345"));
logger.bind("session".to_string(), serde_json::json!("abc-def"));
logger.info("User action logged".to_string())?;
// Remove binding
logger.unbind("user_id");
// Clear all bindings
logger.clear_bindings();
let mut config = LoggerConfig::default();
config.enable_gpu = true;
config.gpu_buffer_size = 2 * 1024 * 1024; // 2MB
logger.configure(config);
logger.enable_gpu()?;
println!("{}", logger.gpu_info());
let mut config = LoggerConfig::default();
config.level = Level::Debug;
config.color = true;
config.json = false;
logger.configure(config);
Create logly.toml:
[logly.configuration]
level = "DEBUG"
auto_sink = true
[logly.display]
color = true
global_console_display = true
global_file_storage = true
[logly.features]
enable_callbacks = true
enable_exception_handling = true
enable_version_check = true
See Configuration Guide for all options.
Full documentation available at: https://muhammad-fiaz.github.io/logly-rs
Run the examples:
# Basic usage
cargo run --example basic
# Advanced features
cargo run --example advanced
# Complete configuration
cargo run --example configuration
# GPU logging (requires CUDA)
cargo run --example gpu_logging --features gpu
# Callbacks and custom colors
cargo run --example callbacks
# File rotation
cargo run --example rotation
# Custom log levels
cargo run --example custom_levels
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_level_priority
# Run benchmarks
cargo bench
If you encounter any bugs or issues:
Contributions welcome! See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License. See the LICENSE file for details.
Current version: 0.0.4
See CHANGELOG.md for release history.
Check for updates:
if let Ok(Some(msg)) = logger.check_version() {
println!("{}", msg);
}
muhammad-fiaz