Ftail
Ftail is a simple logging implementation for the log crate with support for multiple channels, including console output, files, and custom loggers.
Features
- Multiple logging channels: console, formatted console, single file, daily file, and custom
- Level and target filtering
- Optional timestamp formatting and timezone support
- Automatic log rotation and retention
- Use
RUST_LOGenvironment variable for dynamic log level control (use '_env_level' postfix)
Quick Start
Add Ftail to your Cargo.toml:
[]
= "0.3"
Initialize Ftail in your main.rs or lib.rs:
use Ftail;
use LevelFilter;
Configuration Options
| Option | Description | Notes |
|---|---|---|
.datetime_format() |
Set the datetime format | Ex: "%Y-%m-%d %H:%M:%S%.3f" |
.timezone() |
Set the timezone | Requires timezone feature |
.max_file_size() |
Maximum file size in MB | Older logs renamed .old{N} |
.retention_days() |
Number of days to keep log files | Daily file only |
.filter_levels() |
Log only the specified levels | Vec<Level> |
.filter_targets() |
Log only the specified targets | Vec<&str> |
Channels
Console
Logs to the standard output without formatting.
new
.console
.init?;
Output:
2024-09-13 17:35:18 TRACE console This is a trace message
2024-09-13 17:35:18 DEBUG console This is a debug message
2024-09-13 17:35:18 INFO foo bar
2024-09-13 17:35:18 WARN console This is a warning message
2024-09-13 17:35:18 ERROR console This is an error message
Formatted Console
Logs with formatted and colored output.
new
.formatted_console
.init?;
Output:
2024-09-13 17:35:37 · TRACE
This is a trace message
examples/formatted_console/src/main.rs:9
2024-09-13 17:35:37 · DEBUG
This is a debug message
examples/formatted_console/src/main.rs:11
Single File
Logs to a single file (e.g., logs/demo.log).
new
.single_file
.init?;
append = truekeeps existing logs,falseoverwrites.
Daily File
Logs to daily files in a directory (e.g., logs/2025-09-25.log).
new
.daily_file
.init?;
- Automatically rotates files per day.
Custom Channel
Create your own logger by implementing the log::Log trait:
new
.custom
.datetime_format
.init?;
Output:
19:37:22.402 [DEBUG] This is a debug message
19:37:22.403 [INFO] bar
19:37:22.403 [WARN] This is a warning message
19:37:22.403 [ERROR] This is an error message
Tips
- Use
.console(LevelFilter::Debug)for development. - Use
.daily_file()in production to organize logs by date. - Combine
.max_file_size()and.retention_days()to prevent disk bloat. - Only enable the channels you need to reduce overhead by disabling default features in
Cargo.toml.