Ftail
Ftail is simple logging implementation for the log crate with support for multiple channels.
Usage
Add the following dependencies to your Cargo.toml file:
[]
= "0.2"
Add the following code to your main.rs or lib.rs file:
use Ftail;
use LevelFilter;
new
.console
.daily_file
.init?;
// log messages anywhere in your code
trace!;
debug!;
info!;
warn!;
error!;
You can set the following configuration options:
.datetime_format("%Y-%m-%d %H:%M:%S.3f")to set the datetime format.timezone(ftail::Tz::UTC)to set the timezone [requires featuretimezone].max_file_size(100)to set the maximum file size in MB (will move older logs to .old{N}).retention_days(7)to set the number of days to keep the log files (daily file only).filter_levels(vec![Level::Debug, Level::Error])only log messages with the specified levels.filter_targets(vec!["foo", "bar"])only log messages with the specified targets
Channels
Console
Logs to the standard output without any formatting.
The stdout channel takes the following parameters:
level: the minumum log level to log
new
.console
.init?;
Formatted Console
Logs to the standard output with formatted and colored output.
The console channel takes the following parameters:
level: the minumum log level to log
new
.formatted_console
.init?;
Single file
Logs to the single log file logs/demo.log.
The single_file channel takes the following parameters:
path: the path to the log fileappend: whether to append to the log file or overwrite itlevel: the minumum log level to log
new
.single_file
.init?;
Daily file
Logs to a daily log file in the logs directory. The log files have the following format: YYYY-MM-DD.log.
The daily_file channel takes the following parameters:
dir: the directory to store the log fileslevel: the minumum log level to log
new
.daily_file
.init?;
Custom channel
Create your own log channel.
new
.custom
.datetime_format
.init?;
// the custom logger implementation