Struct flexi_logger::writers::FileLogWriterBuilder
source · pub struct FileLogWriterBuilder { /* private fields */ }
Expand description
Builder for FileLogWriter
.
Implementations§
source§impl FileLogWriterBuilder
impl FileLogWriterBuilder
Simple methods for influencing the behavior of the FileLogWriter
.
sourcepub fn print_message(self) -> FileLogWriterBuilder
pub fn print_message(self) -> FileLogWriterBuilder
Makes the FileLogWriter
print an info message to stdout
when a new file is used for log-output.
sourcepub fn format(self, format: FormatFunction) -> FileLogWriterBuilder
pub fn format(self, format: FormatFunction) -> FileLogWriterBuilder
Makes the FileLogWriter
use the provided format function for the log entries,
rather than the default (formats::default_format).
sourcepub fn directory<S: Into<String>>(self, directory: S) -> FileLogWriterBuilder
pub fn directory<S: Into<String>>(self, directory: S) -> FileLogWriterBuilder
Specifies a folder for the log files.
If the specified folder does not exist, the initialization will fail. By default, the log files are created in the folder where the program was started.
sourcepub fn suffix<S: Into<String>>(self, suffix: S) -> FileLogWriterBuilder
pub fn suffix<S: Into<String>>(self, suffix: S) -> FileLogWriterBuilder
Specifies a suffix for the log files. The default is “log”.
sourcepub fn suppress_timestamp(self) -> FileLogWriterBuilder
pub fn suppress_timestamp(self) -> FileLogWriterBuilder
Makes the logger not include a timestamp into the names of the log files
sourcepub fn rotate_over_size(self, rotate_over_size: usize) -> FileLogWriterBuilder
pub fn rotate_over_size(self, rotate_over_size: usize) -> FileLogWriterBuilder
Prevents indefinite growth of log files.
By default, the log file is fixed while your program is running and will grow indefinitely. With this option being used, when the log file reaches or exceeds the specified file size, the file will be closed and a new file will be opened.
The rotate-over-size is given in bytes, e.g. rotate_over_size(1_000)
will rotate
files once they reach a size of 1000 bytes.
Note that also the filename pattern changes:
- by default, no timestamp is added to the filename
- the logs are always written to a file with infix
_rCURRENT
- if this file exceeds the specified rotate-over-size, it is closed and renamed to a file
with a sequential number infix,
and then the logging continues again to the (fresh) file with infix
_rCURRENT
Example:
After some logging with your program my_prog
, you will find files like
my_prog_r00000.log
my_prog_r00001.log
my_prog_r00002.log
my_prog_rCURRENT.log
sourcepub fn append(self) -> FileLogWriterBuilder
pub fn append(self) -> FileLogWriterBuilder
Makes the logger append to the given file, if it exists; by default, the file would be truncated.
sourcepub fn discriminant<S: Into<String>>(
self,
discriminant: S
) -> FileLogWriterBuilder
pub fn discriminant<S: Into<String>>(
self,
discriminant: S
) -> FileLogWriterBuilder
The specified String is added to the log file name.
sourcepub fn create_symlink<S: Into<String>>(self, symlink: S) -> FileLogWriterBuilder
pub fn create_symlink<S: Into<String>>(self, symlink: S) -> FileLogWriterBuilder
The specified String will be used on linux systems to create in the current folder a symbolic link to the current log file.
sourcepub fn instantiate(self) -> Result<FileLogWriter, FlexiLoggerError>
pub fn instantiate(self) -> Result<FileLogWriter, FlexiLoggerError>
Produces the FileLogWriter.
source§impl FileLogWriterBuilder
impl FileLogWriterBuilder
Alternative set of methods to control the behavior of the FileLogWriterBuilder
.
Use these methods when you want to control the settings flexibly,
e.g. with commandline arguments via docopts
or clap
.
sourcepub fn o_print_message(self, print_message: bool) -> FileLogWriterBuilder
pub fn o_print_message(self, print_message: bool) -> FileLogWriterBuilder
With true, makes the FileLogWriterBuilder print an info message to stdout, each time when a new file is used for log-output.
sourcepub fn o_directory<S: Into<String>>(
self,
directory: Option<S>
) -> FileLogWriterBuilder
pub fn o_directory<S: Into<String>>(
self,
directory: Option<S>
) -> FileLogWriterBuilder
Specifies a folder for the log files.
If the specified folder does not exist, the initialization will fail. With None, the log files are created in the folder where the program was started.
sourcepub fn o_timestamp(self, use_timestamp: bool) -> FileLogWriterBuilder
pub fn o_timestamp(self, use_timestamp: bool) -> FileLogWriterBuilder
With true, makes the FileLogWriterBuilder include a timestamp into the names of the log files.
sourcepub fn o_rotate_over_size(
self,
rotate_over_size: Option<usize>
) -> FileLogWriterBuilder
pub fn o_rotate_over_size(
self,
rotate_over_size: Option<usize>
) -> FileLogWriterBuilder
By default, and with None, the log file will grow indefinitely. If a size is set, when the log file reaches or exceeds the specified size, the file will be closed and a new file will be opened. Also the filename pattern changes: instead of the timestamp, a serial number is included into the filename.
The size is given in bytes, e.g. o_rotate_over_size(Some(1_000))
will rotate
files once they reach a size of 1 kB.
sourcepub fn o_append(self, append: bool) -> FileLogWriterBuilder
pub fn o_append(self, append: bool) -> FileLogWriterBuilder
If append is set to true, makes the logger append to the given file, if it exists. By default, or with false, the file would be truncated.
sourcepub fn o_discriminant<S: Into<String>>(
self,
discriminant: Option<S>
) -> FileLogWriterBuilder
pub fn o_discriminant<S: Into<String>>(
self,
discriminant: Option<S>
) -> FileLogWriterBuilder
The specified String is added to the log file name.
sourcepub fn o_create_symlink<S: Into<String>>(
self,
symlink: Option<S>
) -> FileLogWriterBuilder
pub fn o_create_symlink<S: Into<String>>(
self,
symlink: Option<S>
) -> FileLogWriterBuilder
If a String is specified, it will be used on linux systems to create in the current folder a symbolic link with this name to the current log file.