Struct flexi_logger::writers::FileLogWriterBuilder
source · pub struct FileLogWriterBuilder { /* private fields */ }
Expand description
Builder for FileLogWriter
.
Implementations§
source§impl FileLogWriterBuilder
impl FileLogWriterBuilder
Methods for influencing the behavior of the FileLogWriter
.
sourcepub fn print_message(self) -> Self
pub fn print_message(self) -> Self
Makes the FileLogWriter
print an info message to stdout
when a new file is used for log-output.
sourcepub fn format(self, format: FormatFunction) -> Self
pub fn format(self, format: FormatFunction) -> Self
Makes the FileLogWriter
use the provided format function for the log entries,
rather than default_format
.
sourcepub fn cleanup_in_background_thread(self, use_background_thread: bool) -> Self
pub fn cleanup_in_background_thread(self, use_background_thread: bool) -> Self
Influences how the cleanup activities
(finding files, deleting files, optionally compressing files) are done
when rotation is used with some Cleanup
variant.
With the synchronous write modes,
the cleanup activities are done by default in a dedicated background thread, to
minimize the blocking impact on your application.
You can avoid this extra thread by calling this method with
use_background_thread = false
; the cleanup is then done synchronously
by the thread that is currently logging and - by chance - causing a file rotation.
With WriteMode::AsyncWith
,
the cleanup activities are always done by the same background thread
that also does the file I/O, this method then has no effect.
sourcepub fn rotate(self, criterion: Criterion, naming: Naming, cleanup: Cleanup) -> Self
pub fn rotate(self, criterion: Criterion, naming: Naming, cleanup: Cleanup) -> Self
Use rotation to prevent 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 the specified criterion, the file will be closed and a new file will be opened.
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
- when the rotation criterion is fulfilled, it is closed and renamed to a file
with another infix (see
Naming
), and then the logging continues again to the (fresh) file with infix_rCURRENT
.
Example:
After some logging with your program my_prog
and rotation with Naming::Numbers
,
you will find files like
my_prog_r00000.log
my_prog_r00001.log
my_prog_r00002.log
my_prog_rCURRENT.log
The cleanup parameter allows defining the strategy for dealing with older files.
See Cleanup
for details.
sourcepub fn append(self) -> Self
pub fn append(self) -> Self
Makes the logger append to the given file, if it exists; by default, the file would be truncated.
sourcepub fn create_symlink<P: Into<PathBuf>>(self, symlink: P) -> Self
pub fn create_symlink<P: Into<PathBuf>>(self, symlink: P) -> Self
The specified String will be used on unix systems to create in the current folder a symbolic link to the current log file.
sourcepub fn use_windows_line_ending(self) -> Self
pub fn use_windows_line_ending(self) -> Self
Use Windows line endings, rather than just \n
.
sourcepub fn write_mode(self, write_mode: WriteMode) -> Self
pub fn write_mode(self, write_mode: WriteMode) -> Self
Sets the write mode for the FileLogWriter
.
See WriteMode
for more (important!) details.
sourcepub fn try_build(self) -> Result<FileLogWriter, FlexiLoggerError>
pub fn try_build(self) -> Result<FileLogWriter, FlexiLoggerError>
sourcepub fn try_build_with_handle(
self
) -> Result<(ArcFileLogWriter, FileLogWriterHandle), FlexiLoggerError>
pub fn try_build_with_handle( self ) -> Result<(ArcFileLogWriter, FileLogWriterHandle), FlexiLoggerError>
Produces the FileLogWriter
and a handle that is connected with it.
This allows handing out the FileLogWriter
instance to methods that consume it, and still
be able to influence it via the handle.
Errors
FlexiLoggerError::Io
if the specified path doesn’t work.
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) -> Self
pub fn o_print_message(self, print_message: bool) -> Self
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_rotate(
self,
rotate_config: Option<(Criterion, Naming, Cleanup)>
) -> Self
pub fn o_rotate( self, rotate_config: Option<(Criterion, Naming, Cleanup)> ) -> Self
By default, and with None, the log file will grow indefinitely.
If a rotate_config
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.
The cleanup strategy allows delimiting the used space on disk.
sourcepub fn o_append(self, append: bool) -> Self
pub fn o_append(self, append: bool) -> Self
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_create_symlink<S: Into<PathBuf>>(self, symlink: Option<S>) -> Self
pub fn o_create_symlink<S: Into<PathBuf>>(self, symlink: Option<S>) -> Self
If a String is specified, it will be used on unix systems to create in the current folder a symbolic link with this name to the current log file.