| Crates.io | FreedomLogger |
| lib.rs | FreedomLogger |
| version | 1.1.0 |
| created_at | 2025-09-08 07:50:23.695925+00 |
| updated_at | 2025-09-09 06:57:58.795418+00 |
| description | A professional, reusable logging library with pattern formatting, log rotation, and file management |
| homepage | https://github.com/Jurgen-Be/FreedomLogger |
| repository | https://github.com/Jurgen-Be/FreedomLogger |
| max_upload_size | |
| id | 1828953 |
| size | 104,403 |
A professional, thread-safe logging library for Rust with automatic rotation, multiple output formats, and error-proof operation.
Add to your Cargo.toml:
[dependencies]
freedom_logger = "1.1.0"
Or use cargo:
cargo add freedom_logger
use freedom_logger::{log_init, log_info, log_warning, log_error, Pattern};
fn main() {
// Initialize logger once
log_init(Pattern::Basic, "./logs", "myapp");
// Log anywhere in your application
log_info("Application started");
log_warning("This is a warning");
log_error("Something went wrong");
}
FreedomLogger now supports both simple functions and powerful formatting macros:
use freedom_logger::{log_error, log_warning, log_info, log_debug, log_trace};
log_error("Critical system failure");
log_warning("Deprecated API usage detected");
log_info("User authentication successful");
log_debug("Processing request payload");
log_trace("Entering function calculate_metrics");
use freedom_logger::{log_error, log_warning, log_info, log_debug, log_trace};
// Support for formatted strings with automatic type handling
log_info!("User {} logged in successfully", username);
log_debug!("Database path: {:?}", database_path); // Works with any Debug type!
log_error!("Failed to connect to {}: {}", host, error_message);
log_warning!("Processing {} items in batch {}", item_count, batch_id);
// Complex types work automatically
let config = MyConfig { host: "localhost", port: 5432 };
log_debug!("Server config: {:?}", config);
// Multiple format specifiers
log_info!("User {} from {} logged in at {}", user_id, ip_address, timestamp);
Before v1.1.0 (would cause compilation errors):
let database_path = PathBuf::from("/var/lib/app.db");
log_debug("Database path: {:?}", database_path); // โ Error!
After v1.1.0 (works perfectly):
let database_path = PathBuf::from("/var/lib/app.db");
log_debug!("Database path: {:?}", database_path); // โ
Perfect!
use freedom_logger::{log_init, Pattern};
// Logs all levels, 10MB files, 5 backups
log_init(Pattern::Basic, "/var/log/myapp", "application");
use freedom_logger::{log_init_with_level, Pattern, LogLevel};
// Only log WARNING and ERROR messages
log_init_with_level(Pattern::Detailed, "./logs", "app", LogLevel::Warning);
use freedom_logger::{log_init_with_rotation, Pattern, LogLevel};
// 50MB files, keep 10 backups
log_init_with_rotation(
Pattern::Json,
"./logs",
"service",
LogLevel::Info,
50 * 1024 * 1024, // 50MB
10 // 10 backup files
);
[2025-09-09 14:30:45] INFO: User logged in successfully
[2025-09-09 14:30:46] ERROR: Database connection failed
[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
{"timestamp":"2025-09-09 14:30:45","level":"INFO","message":"User logged in successfully","file":"main.rs","line":42,"thread":"main"}
{"timestamp":"2025-09-09 14:30:46","level":"ERROR","message":"Database connection failed","file":"db.rs","line":158,"thread":"worker-1"}
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.
FreedomLogger is designed to be error-proof:
logger_errors.logFreedomLogger is fully thread-safe:
use std::thread;
use freedom_logger::{log_init, Pattern};
fn main() {
log_init(Pattern::Basic, "./logs", "threaded_app");
let handles: Vec<_> = (0..10)
.map(|i| {
thread::spawn(move || {
// Both styles work in threads
log_info!("Message from thread {}", i);
log_debug!("Thread {} processing data: {:?}", i, some_data);
})
})
.collect();
for handle in handles {
handle.join().unwrap();
}
}
| 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 |
FreedomLogger automatically uses appropriate file extensions:
.log files.json filesBufWriter for optimal write performanceComplete examples are available in the examples/ directory:
# Basic logging example
cargo run --example basic_usage
# JSON structured logging
cargo run --example json_logging
# High-volume logging with rotation
cargo run --example rotation_demo
# NEW: Formatted logging examples
cargo run --example formatted_logging
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Licensed under the MIT License.
See CHANGELOG for detailed version history.
Built with Rust for performance, safety, and reliability. ๐ฆ