Crate lightning_log

Crate lightning_log 

Source
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§

LightningLogger
The main lightning logger
LogEntry
A log entry containing all necessary information
LoggerConfig
Configuration for the lightning logger
OutputWriter
Output writer that handles multiple destinations

Enums§

LogDestination
Output destination for log entries
LogLevel
Log levels

Traits§

FastSerialize
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