Loggix
A high-performance, async-first logging framework for Rust with Kafka integration.
Features
- Flexible logging levels (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, PANIC)
- Structured logging with key-value pairs
- Customizable formatters (text and JSON included)
- Asynchronous logging support
log_asyncmethod for async contexts- Non-blocking operations
- Tokio runtime integration
- Hook system for log processing and forwarding
- Sync and async hook support
- Multiple hooks per logger
- Level-based filtering
- Kafka integration with support for:
- Asynchronous message delivery
- Custom message keys via fields
- Topic configuration
- Error handling and retries
- Automatic topic creation
- Message key routing
- Thread-safe logging
- Zero-allocation logging paths
- Configurable output destinations
- Colorized console output (optional)
- Comprehensive benchmarks
- Full test coverage
Installation
Add this to your Cargo.toml:
[]
= "1.0"
Quick Start
Basic Logging
use ;
// Create a logger
let logger = new.build;
// Log a message
let mut fields = new;
fields.insert;
logger.log.unwrap;
// Async logging
let mut fields = new;
fields.insert;
logger.log_async.await.unwrap;
Structured Logging with JSON
use ;
use Value;
let logger = new
.formatter
.build;
let mut fields = new;
fields.insert;
fields.insert;
logger.log.unwrap;
Kafka Integration
Setting up Kafka
- Start the Kafka environment:
- Create a logger with Kafka hook:
use ;
use Value;
// Create a Kafka hook with message key support
let kafka_hook = new
.unwrap
.with_key_field;
// Create a logger with the Kafka hook
let logger = new
.add_hook
.build;
// Log a message with a correlation ID for message routing
let mut fields = new;
fields.insert;
fields.insert;
logger.log_async.await.unwrap;
Message Key Support
The Kafka hook supports setting a field as the message key:
// Set up hook with a key field
let kafka_hook = new
.unwrap
.with_key_field;
// Any log message with the tenant_id field will use it as the Kafka message key
let mut fields = new;
fields.insert;
logger.log_async.await.unwrap;
This enables:
- Message routing based on keys
- Message partitioning
- Message deduplication
- Message ordering within partitions
Async Support
Both the logger and hooks support async operations:
// Async logging with hooks
logger.log_async.await?;
// Hooks automatically use async operations when available
Examples
See the examples/ directory for more examples:
- Basic logging
- Custom formatters
- Kafka integration
- Async logging
- Structured logging
- Error handling
Benchmarks
Run the benchmarks:
Example benchmark results:
- Sync logging: ~1800ns/iter
- Async logging: ~2000ns/iter
- Kafka logging: ~10000ns/iter (network latency not included)
Configuration
YAML Configuration
Create a config.yaml file:
kafka:
bootstrap_servers: "localhost:9092"
group_id: "logger_group"
auto_offset_reset: "earliest"
socket_timeout_ms: 3000
session_timeout_ms: 6000
replication_factor: 1
partitions: 1
Performance Tips
- Use
log_asyncin async contexts - Reuse field collections when possible
- Consider message key strategy for Kafka partitioning
- Use appropriate log levels to minimize processing
- Configure appropriate batch sizes for Kafka
Roadmap
- ElasticSearch integration
- Log rotation
- Log compression
- Sampling and filtering
- OpenTelemetry integration
- Prometheus metrics
- Log aggregation
- Log analytics
Changelog
For a detailed list of changes between versions, please see our CHANGELOG.
License
This project is licensed under the MIT License - see the LICENSE file for details.