LogFusion
Tracing-native logging macros with structured logging support and enhanced error handling for Rust.
LogFusion provides a clean, modern logging interface built on top of the tracing ecosystem, offering structured logging, automatic initialization, and powerful error handling capabilities.
โจ Key Features
- ๐ฏ Tracing-Native - Built on the modern
tracingecosystem for superior observability - ๐ Structured Logging - First-class support for structured fields and metadata
- ๐ Auto-Initialization - Automatic tracing subscriber setup with smart defaults
- ๐ Log Crate Bridge - Seamless compatibility with libraries using the
logcrate - ๐ FFI Callback Support - Optional integration with Python, Node.js, C/C++, and WebAssembly
- โก Enhanced Error Handling - Dual-syntax
define_errors!macro with LogFusion format + thiserror compatibility - ๐ ๏ธ Zero Config - Works out of the box with sensible defaults
- ๐ง Spans & Instrumentation - Full support for tracing spans and
#[instrument]
๐ Quick Start
Add LogFusion to your project
[]
= "0.2"
# Optional: Add tracing-subscriber for advanced configuration
= { = "0.3", = ["env-filter", "json"] }
Basic Usage
use ;
Enhanced Error Handling
New LogFusion Format (Simplified & Powerful):
use define_errors;
// ๐ LogFusion Format - Clean, attribute-based syntax
define_errors!
// Multiple error types in one macro
define_errors!
Traditional Thiserror Syntax (Fully Compatible):
define_errors!
๐ Error Introspection & Monitoring
New in v0.2: All generated error enums include an error_info() method for monitoring and debugging:
use define_errors;
use HashMap;
define_errors!
Use Cases for error_info():
- ๐ Metrics Collection - Build error dashboards and SLA monitoring
- ๐จ Alerting Systems - Set up automated alerts based on error patterns
- ๐ Debugging Tools - Analyze error patterns in production
- ๐ Business Intelligence - Track error rates by component/severity
๐ฏ Why LogFusion?
๐ Dual-Syntax Error Handling
LogFusion v0.2 introduces a revolutionary dual-syntax approach to error definitions:
LogFusion Format Benefits:
- โ
Cleaner Syntax - No repetitive
#[error(...)]attributes - โ
Attribute-Based Logging -
[level = warn, target = "app::db"]syntax - โ Multiple Types - Define multiple error enums in one macro call
- โ
Auto Source Detection - Fields named
sourceautomatically become#[source] - โ
Mixed Variants - Unit (
{}) and struct variants in same enum - โ
Field Interpolation -
"Failed to connect to {host}:{port}"syntax
Performance & Maintainability:
- ๐ 64% Macro Optimization - Reduced from 998 to 358 lines while adding features
- ๐งน 11 Comprehensive Tests - Every scenario covered with battle-tested reliability
- ๐ Full Backward Compatibility - Existing thiserror syntax continues to work
- ๐ Structured Logging Integration - Seamless tracing ecosystem integration
Modern Tracing Ecosystem
Built on tracing, the modern standard for Rust observability:
- Structured logging - Attach key-value metadata to log events
- Spans - Track operations across async boundaries
- Instrumentation - Automatic span creation with
#[instrument] - Rich ecosystem - Compatible with OpenTelemetry, Jaeger, Datadog, and more
Auto-Initialization
No boilerplate setup required:
use info;
Structured Logging Made Easy
use info;
// Rich, structured metadata
info!;
Backward Compatibility
Works seamlessly with existing log crate usage:
// These both work and are captured by LogFusion
info!;
info!;
๐ Structured Logging
LogFusion excels at structured logging, making your logs machine-readable and perfect for modern observability platforms:
use ;
// User authentication
info!;
// Payment processing
error!;
// Spans with structured context
let span = info_span!;
let _enter = span.enter;
info!;
info!;
๐๏ธ Spans and Instrumentation
Full support for tracing spans and automatic instrumentation:
use ;
use instrument;
async
๐๏ธ Configuration
Environment Variables
LogFusion respects standard tracing environment variables:
# Set log level
RUST_LOG=debug
# Target specific modules
RUST_LOG=myapp::database=debug,myapp::auth=info
# Filter by span names
RUST_LOG=process_order=trace
Custom Initialization
For advanced use cases, you can configure tracing manually:
use ;
๐ Documentation & Examples
- API Documentation - Full API reference
- Cookbook - Real-world patterns and best practices
- Examples - Runnable example code
Key Examples
logfusion_format_showcase.rs- Complete LogFusion format demonstration with all featureslogfusion_source_chaining.rs- Automatic source chaining with fields named "source"field_interpolation_demo.rs- Dual-syntax field interpolation comparisonstructured_logging_demo.rs- Manual + automatic structured loggingadvanced_tracing_features.rs- Spans, instrumentation, and ecosystem integration
๐ FFI and Callback Support
LogFusion includes optional FFI callback support for integrating with other languages:
[]
= { = "0.2", = ["callback"] }
With the callback feature enabled, LogFusion can route log messages to external callbacks, enabling integration with:
- Python (via PyO3)
- Node.js (via Neon)
- C/C++ applications
- WebAssembly modules
- Any FFI-compatible language
use ;
The callback system allows external applications to receive structured log data while LogFusion continues to work normally with the tracing ecosystem.
๐ง Feature Flags
LogFusion uses minimal feature flags:
[]
= { = "0.2", = ["callback"] }
callback- Enable FFI callback support (optional, for cross-language integrations)
๐ Use Cases
Perfect for:
- โ Modern Rust applications wanting structured observability
- โ Microservices needing rich context and tracing
- โ Cross-language projects requiring log bridging to Python, Node.js, or C/C++
- โ Rust libraries embedded in other language ecosystems
- โ
Applications migrating from
logtotracing - โ Projects needing automatic error logging with proper types
Consider alternatives if:
- โ You just need basic text logging (use
log+env_logger) - โ You're happy with your current logging setup
- โ You don't need structured logging or error handling
๐ค Ecosystem Compatibility
LogFusion works seamlessly with the entire tracing ecosystem:
tracing-subscriber- Flexible subscriber implementationstracing-opentelemetry- OpenTelemetry integrationconsole-subscriber- Tokio Console integrationtracing-appender- File output and rotationtracing-flame- Flamegraph profiling
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Built on top of the excellent tracing and thiserror crates. Special thanks to the Rust logging ecosystem maintainers.