Expand description
§Lightning Log
Ultra-fast zero-allocation logging designed for high-frequency trading and low-latency systems.
§Features
- Sub-100ns logging latency in the critical path
- Zero allocations during logging calls
- Binary serialization for maximum performance
- Lock-free communication between threads
- CPU affinity support for logging thread
- Structured logging with message IDs
- Compile-time optimizations via macros
§Quick Start
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={}");
let volume = 1000.0;
let price = 150.25;
let symbol = "AAPL";
// Ultra-fast logging (typically <100ns)
lightning_info!(1001, volume, price, symbol);
lightning_debug!(1002, price);
lightning_warn!(1003, true, 42i32);
§Advanced Configuration
For production use, you can configure file output and other advanced features:
use lightning_log::*;
use std::path::PathBuf;
// Configure for production use
let config = LoggerConfig {
channel_capacity: 100_000,
destinations: vec![
LogDestination::Stdout,
LogDestination::File(PathBuf::from("logs/trading.log")),
],
file_buffer_size: 64 * 1024, // 64KB buffer
enable_cpu_affinity: true,
};
init_lightning_log_with_config(config)?;
// Register message formats
register_message_format(1001, "Trade executed: 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();
std::thread::sleep(std::time::Duration::from_millis(100)); // Allow time for processing
Macros§
- __
size_ hint - Calculate size hint for multiple arguments
- lightning_
debug - Debug level logging
- lightning_
error - Error level logging
- lightning_
info - Info level logging
- lightning_
log - Main logging macro
- lightning_
warn - Warning level logging
Structs§
- Lightning
Logger - The main lightning logger
- LogEntry
- A log entry containing all necessary information
- Logger
Config - Configuration for the lightning logger
- Output
Writer - Output writer that handles multiple destinations
Enums§
- LogDestination
- Output destination for log entries
- LogLevel
- Log levels
Traits§
- Fast
Serialize - Trait for types that can be efficiently serialized for logging
Functions§
- get_
global_ logger - Get a reference to the global logger for manual shutdown control
- init_
lightning_ log - Initialize the global lightning logger with default configuration
- init_
lightning_ log_ with_ capacity - Initialize with custom capacity
- init_
lightning_ log_ with_ config - Initialize with custom configuration
- register_
message_ format - Register a message format for human-readable output
- shutdown_
lightning_ log - Initiate graceful shutdown of the global logger
- wait_
for_ shutdown - Wait for the global logger to complete shutdown