Function fruitbasket::create_logger
[−]
[src]
pub fn create_logger(
_filename: &str,
_dir: LogDir,
_max_size_mb: u32,
_backup_count: u32
) -> Result<String, String>
Enable logging to rolling log files with Rust log
library
Requires the 'logging' feature to be specified at compile time.
This is a helper utility for configuring the Rust log
and log4rs
libraries to redirect the log
macros (info!()
, warn!()
, err!()
, etc)
to both stdout and a rotating log file on disk.
If you specify the Home directory with a log named ".fruit.log" and a
backup count of 3, eventually you will end up with the files ~/.fruit.log
,
~/.fruit.log.1
, ~/.fruit.log.2
, and ~/.fruit.log.3
The maximum disk space used by the log files, in megabytes, will be:
(backup_count + 1) * max_size_mb
Arguments
filename
- Filename for the log file, without path
dir
- Directory to save log files in. This is provided as an enum,
LogDir
, which offers some standard logging directories, or allows
specification of any custom directory.
max_size_mb
- Max size (in megabytes) of the log file before it is rolled
into an archive file in the same directory.
backup_count
- Number of archived log files to keep before deleting old
logs.
Returns
Full path to opened log file on disk