| Crates.io | lightning-log |
| lib.rs | lightning-log |
| version | 1.1.0 |
| created_at | 2025-08-21 12:09:56.371222+00 |
| updated_at | 2025-08-21 13:50:24.209139+00 |
| description | Ultra-fast zero-allocation logging for high-frequency trading and low-latency systems |
| homepage | |
| repository | https://github.com/simplysabir/lightning-log |
| max_upload_size | |
| id | 1804762 |
| size | 88,254 |
Ultra-fast zero-allocation logging for high-frequency trading and low-latency systems
Comprehensive benchmarks show Lightning Log's exceptional performance for real-world logging scenarios:
| Implementation | Per Message | Total Time (100k msgs) | Throughput | Notes |
|---|---|---|---|---|
| Lightning Log | 190.4ns | 19ms | 5.26M msgs/sec | β Full logging pipeline |
| Log Crate + Subscriber | 45,380.9ns | 4.5s | 22.2K msgs/sec | β οΈ 238x slower |
| Implementation | Critical Path Latency | Use Case Suitability |
|---|---|---|
| Lightning Log | ~73ns | β HFT, Low-Latency Trading |
Standard println! |
~1,432ns | β Too slow for HFT |
| Log Crate (macro only) | ~5.2ns | β No actual logging |
| Log Crate (with I/O) | ~45,381ns | β 238x slower than Lightning |
Lightning Log is the only viable choice:
The log crate is completely unsuitable for HFT:
# Run comprehensive benchmarks
cargo bench
# Run specific benchmark groups
cargo bench --bench logging_benchmark -- logging_comparison
cargo bench --bench logging_benchmark -- high_throughput
# View detailed results
open target/criterion/report/index.html
# Run fair comparison example
cargo run --example log_crate_comparison
Key Insight: Lightning Log processes 238x more messages in the same time as the log crate, making it the only choice for latency-critical applications like HFT.
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β User Code βββββΆβ LogEntry βββββΆβ OutputWriter β
β β β Creation β β β
β lightning_!() β β (~73ns) β β File/Console β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β LightningLogger β
β (Async Thread) β
ββββββββββββββββββββ
use lightning_log::*;
// Initialize the logger (call once at startup)
init_lightning_log()?;
// Register message formats (optional, for human-readable output)
register_message_format(1001, "Trade executed: volume={}, price={}, symbol={}".to_string())?;
let volume = 100.0;
let price = 150.25;
let symbol = "AAPL";
// Ultra-fast logging (typically <100ns)
lightning_info!(1001, volume, price, symbol);
use lightning_log::*;
use std::path::PathBuf;
// Configure for production use
let config = LoggerConfig {
channel_capacity: 1_000_000, // Large buffer for high throughput
destinations: vec![
LogDestination::Stdout, // Console output
LogDestination::File(PathBuf::from("logs/trading.log")),
],
file_buffer_size: 128 * 1024, // 128KB buffer
enable_cpu_affinity: true, // Pin to specific CPU core
};
init_lightning_log_with_config(config)?;
// Register message formats
register_message_format(1001, "Trade: volume={}, price={}, symbol={}".to_string())?;
// Your trading logic here...
let volume = 1000.0;
let price = 150.25;
let symbol = "AAPL";
lightning_info!(1001, volume, price, symbol);
// Graceful shutdown (important for production)
shutdown_lightning_log();
lightning-log/
βββ src/
β βββ lib.rs # Main library implementation
βββ benches/
β βββ logging_benchmark.rs # Comprehensive performance benchmarks
βββ examples/
β βββ basic_usage.rs # Basic usage example
β βββ trading_simulation.rs # High-frequency trading simulation
βββ target/
β βββ criterion/ # Benchmark results and reports
βββ README.md # This file
Add to your Cargo.toml:
[dependencies]
lightning-log = "1.1.0"
For development and benchmarking:
[dev-dependencies]
criterion = "0.5"
rand = "0.8"
init_lightning_log() - Initialize with default configurationinit_lightning_log_with_capacity(capacity: usize) - Initialize with custom channel capacityinit_lightning_log_with_config(config: LoggerConfig) - Initialize with full configurationlightning_debug!(message_id, args...) - Debug level logginglightning_info!(message_id, args...) - Info level logginglightning_warn!(message_id, args...) - Warning level logginglightning_error!(message_id, args...) - Error level loggingLoggerConfig - Main configuration structureLogDestination - Output destination (Stdout, Stderr, File, Multiple)register_message_format(id, format) - Register human-readable format stringsshutdown_lightning_log() - Initiate graceful shutdownget_global_logger() - Get reference to logger for manual control# Run all benchmarks
cargo bench
# Run specific benchmark group
cargo bench --bench logging_benchmark -- logging_comparison
# Generate HTML reports
cargo bench --bench logging_benchmark
# View benchmark results
open target/criterion/report/index.html
println! for equivalent functionalityContributions are welcome! Please feel free to submit a Pull Request.
# Clone the repository
git clone https://github.com/simplysabir/lightning-log.git
cd lightning-log
# Run tests
cargo test
# Run benchmarks
cargo bench
# Run examples
cargo run --example basic_usage
cargo run --example trading_simulation
cargo run --example log_crate_comparison
Licensed under :
at your option.
This implementation is based on the paper:
init_lightning_log() before loggingshutdown_lightning_log() for clean terminationFor questions or support:
Built with β€οΈ for high-performance Rust applications