Traccia 📝
A zero-dependency, all-in-one flexible logging framework for Rust applications.
Overview
This crate provides a configurable logging system that supports multiple output targets, customizable formatting, and different log levels. It can be used in both synchronous (blocking) and asynchronous contexts.
Features
- Multiple Log Levels: Trace, Debug, Info, Warning, Error
- Flexible Output Targets: Console, File, and extensible for custom targets
- Customizable Formatting: Define your own log message formatting
- Colored Output: Terminal-friendly colored output with automatic stripping for files
- Async & Blocking Modes: Choose between synchronous or asynchronous logging
- Thread-Safe: Designed for concurrent applications
- Macro-Based API: Simple, expressive logging interface
Installation
Add this to your Cargo.toml:
[]
= "2.2.5"
Quick Start
use ;
Configuration
Basic Initialization
// Initialize with default settings (Info level, Console output)
init_default;
// Initialize with specific log level
init;
Custom Configuration
use ;
// Create a custom configuration
let config = Config ;
// Initialize with custom config
init_with_config;
Custom Formatter
use ;
;
let config = Config ;
Usage Examples
Basic Logging
trace!;
debug!;
info!;
warn!;
error!;
fatal!;
File Logging
use ;
// Create a file target
let file_target = new.expect;
// Configure with file target
let config = Config ;
// Initialize with this config
init_with_config;
Multiple Targets
use ;
// Configure with both console and file targets
let config = Config ;
init_with_config;
Async Logging
This will be the default implementation.
If you wish to change to a blocking logger,
enable the blocking feature.
use ;
Creating Custom Targets
You can implement the Target trait to create custom log destinations:
use ;
// Use it
let config = Config ;
Performance Considerations
- Blocking vs Async: Choose the appropriate mode based on your application needs
- Level Filtering: Set appropriate log levels in production to minimize overhead
- Format Complexity: Complex formatters may introduce additional performance costs
Integration with Other Libraries
This library is designed to be standalone!
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.