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)
- 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
Add to your Cargo.toml
:
[]
= { = "https://github.com/Jurgen-Be/FreedomLogger" }
Basic usage:
use ;
Installation
Usage Examples
Basic Initialization
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;
Custom Rotation Settings
use ;
// 50MB files, keep 10 backups
log_init_with_rotation;
Logging Functions
use ;
log_error;
log_warning;
log_info;
log_debug;
log_trace;
Output Patterns
Basic Pattern
[2025-09-08 14:30:45] INFO: User logged in successfully
[2025-09-08 14:30:46] ERROR: Database connection failed
Detailed Pattern
[2025-09-08 14:30:45] [main.rs:42] INFO: User logged in successfully
[2025-09-08 14:30:46] [db.rs:158] ERROR: Database connection failed
JSON Pattern
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 Handling
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 Options
Initialization Functions
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 (Hierarchical)
- ERROR - Critical failures, system errors
- WARNING - Potential issues, deprecated usage
- INFO - General application flow information
- DEBUG - Detailed debugging information
- TRACE - Very verbose tracing information
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
Requirements
- Rust 1.70 or later
- Dependencies: chrono (timestamps), tempfile (dev/testing only)
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Roadmap
Version 2.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
Version 1.x (Maintenance)
- Bug fixes and performance improvements
- Additional output formats
- Extended platform support
License
Licensed under :
- MIT License
Changelog
See [CHANGELOG] for detailed version history.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: docs.rs/FreedomLogger
Built with Rust for performance, safety, and reliability.