FreedomLogger ๐ฆ
A professional, thread-safe logging library for Rust with automatic rotation, multiple output formats, and error-proof operation.
โจ Features
- Multiple log levels with filtering (ERROR, WARNING, INFO, DEBUG, TRACE)
- Flexible logging API - Both simple functions and formatted macros
- Various output patterns from basic to JSON structured logging
- Automatic log rotation based on configurable file size limits
- Thread-safe concurrent logging with internal synchronization
- Error-proof operation - internal errors never crash your application
- Minimal dependencies - only chrono for timestamps
- Easy initialization - single function call setup
๐ Quick Start
Installation
Add to your Cargo.toml
:
[]
= "1.1.0"
Or use cargo:
Basic usage:
use ;
๐ New in v1.1.0: Formatted Logging Macros
FreedomLogger now supports both simple functions and powerful formatting macros:
Simple Functions (Original)
use ;
log_error;
log_warning;
log_info;
log_debug;
log_trace;
New Formatting Macros
use ;
// Support for formatted strings with automatic type handling
log_info!;
log_debug!; // Works with any Debug type!
log_error!;
log_warning!;
// Complex types work automatically
let config = MyConfig ;
log_debug!;
// Multiple format specifiers
log_info!;
Why Use the Macros?
Before v1.1.0 (would cause compilation errors):
let database_path = from;
log_debug; // โ Error!
After v1.1.0 (works perfectly):
let database_path = from;
log_debug!; // โ
Perfect!
๐ Initialization Options
Basic Setup
use ;
// Logs all levels, 10MB files, 5 backups
log_init;
With Log Level Filtering
use ;
// Only log WARNING and ERROR messages
log_init_with_level;
Full Configuration
use ;
// 50MB files, keep 10 backups
log_init_with_rotation;
๐ Output Formats
Basic Pattern
[2025-09-09 14:30:45] INFO: User logged in successfully
[2025-09-09 14:30:46] ERROR: Database connection failed
Detailed Pattern (with source location)
[2025-09-09 14:30:45] [main.rs:42] INFO: User logged in successfully
[2025-09-09 14:30:46] [db.rs:158] ERROR: Database connection failed
JSON Pattern (structured logging)
๐ Automatic Log Rotation
FreedomLogger automatically rotates log files when they exceed the configured size:
app.log (current log file)
app.1.log (most recent backup)
app.2.log (older backup)
app.N.log (oldest backup, deleted when limit reached)
Default settings: 10MB max file size, 5 backup files retained.
๐ก๏ธ Error-Proof Operation
FreedomLogger is designed to be error-proof:
- Never panics - Internal errors are handled gracefully
- Silent operation - Logging failures don't interrupt your application
- Separate error log - Internal issues logged to
logger_errors.log
- Automatic fallbacks - Invalid configurations use safe defaults
- Directory creation - Creates log directories automatically
๐งต Thread Safety
FreedomLogger is fully thread-safe:
use thread;
use ;
๐ Configuration Quick Reference
Function | Log Level | Rotation | Use Case |
---|---|---|---|
log_init() |
All levels | Default (10MB, 5 backups) | Development, testing |
log_init_with_level() |
Filtered | Default (10MB, 5 backups) | Production with filtering |
log_init_with_rotation() |
Filtered | Custom | High-volume production |
๐ Log Levels
- ERROR - Critical failures, system errors
- WARNING - Potential issues, deprecated usage
- INFO - General application flow information
- DEBUG - Detailed debugging information
- TRACE - Very verbose tracing information
๐จ Available Patterns
- Basic - Simple timestamp, level, message format
- Detailed - Includes source file and line number
- Extended - Adds thread information (planned)
- JSON - Structured logging for analysis tools
- Custom - User-defined format strings (planned)
๐ File Extensions
FreedomLogger automatically uses appropriate file extensions:
- Text patterns (Basic, Detailed, Extended, Custom) โ
.log
files - JSON pattern โ
.json
files
โก Performance
- Buffered I/O - Uses
BufWriter
for optimal write performance - Minimal allocations - Efficient string formatting and memory usage
- Thread synchronization - Mutex-protected writes prevent data corruption
- Lazy initialization - Logger components created only when needed
๐ Examples
Complete examples are available in the examples/
directory:
# Basic logging example
# JSON structured logging
# High-volume logging with rotation
# NEW: Formatted logging examples
๐ Requirements
- Rust 1.70 or later
- Dependencies: chrono (timestamps), tempfile (dev/testing only)
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
๐ฃ๏ธ Roadmap
v2.0.0 (Planned)
- Database integration for direct log storage
- Time-based rotation (daily, weekly, monthly)
- Async logging for high-performance applications
- Enhanced caller location tracking
- Full custom pattern parsing
Ongoing
- Bug fixes and performance improvements
- Additional output formats
- Extended platform support
๐ License
Licensed under the MIT License.
See CHANGELOG for detailed version history.
๐ Links
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: docs.rs/freedom_logger
Built with Rust for performance, safety, and reliability. ๐ฆ