Struct spdlog::sink::FileSinkBuilder
source · pub struct FileSinkBuilder<ArgPath> { /* private fields */ }
Expand description
The builder of FileSink
.
§Note
The generics here are designed to check for required fields at compile time, users should not specify them manually and/or depend on them. If the generic concrete types or the number of generic types are changed in the future, it may not be considered as a breaking change.
§Examples
-
Building a
FileSink
.use spdlog::sink::FileSink; let sink: FileSink = FileSink::builder() .path("/path/to/log_file") // required // .truncate(true) // optional, defaults to `false` .build()?;
-
If any required parameters are missing, a compile-time error will be raised.
ⓘuse spdlog::sink::FileSink; let sink: FileSink = FileSink::builder() // .path("/path/to/log_file") // required .truncate(true) // optional, defaults to `false` .build()?;
Implementations§
source§impl<ArgPath> FileSinkBuilder<ArgPath>
impl<ArgPath> FileSinkBuilder<ArgPath>
sourcepub fn path<P>(self, path: P) -> FileSinkBuilder<PathBuf>
pub fn path<P>(self, path: P) -> FileSinkBuilder<PathBuf>
The path of the log file.
This parameter is required.
sourcepub fn truncate(self, truncate: bool) -> Self
pub fn truncate(self, truncate: bool) -> Self
If it is true, the existing contents of the filewill be discarded.
This parameter is optional, and defaults to false
.
sourcepub fn level_filter(self, level_filter: LevelFilter) -> Self
pub fn level_filter(self, level_filter: LevelFilter) -> Self
Specifies a log level filter.
This parameter is optional, and defaults to LevelFilter::All
.
sourcepub fn formatter(self, formatter: Box<dyn Formatter>) -> Self
pub fn formatter(self, formatter: Box<dyn Formatter>) -> Self
Specifies a formatter.
This parameter is optional, and defaults to FullFormatter
.
sourcepub fn error_handler(self, handler: ErrorHandler) -> Self
pub fn error_handler(self, handler: ErrorHandler) -> Self
Specifies an error handler.
This parameter is optional, and defaults no handler, see Sink::set_error_handler
for details.
source§impl FileSinkBuilder<PathBuf>
impl FileSinkBuilder<PathBuf>
sourcepub fn build(self) -> Result<FileSink>
pub fn build(self) -> Result<FileSink>
Builds a FileSink
.
§Errors
If an error occurs opening the file, Error::CreateDirectory
or
Error::OpenFile
will be returned.