Struct flexi_logger::FileSpec
source · pub struct FileSpec { /* private fields */ }
Expand description
Builder object for specifying the name and path of the log output file.
assert_eq!(
FileSpec::default()
.directory("/a/b/c")
.basename("foo")
.suppress_timestamp()
.suffix("bar"),
FileSpec::try_from("/a/b/c/foo.bar").unwrap()
);
Implementations§
source§impl FileSpec
impl FileSpec
sourcepub fn try_from<P: Into<PathBuf>>(p: P) -> Result<Self, FlexiLoggerError>
pub fn try_from<P: Into<PathBuf>>(p: P) -> Result<Self, FlexiLoggerError>
The provided path should describe a log file. If it exists, it must be a file, not a folder. If necessary, parent folders will be created.
Errors
FlexiLoggerError::OutputBadFile
if the given path exists and is a folder.
Panics
Panics if the basename of the given path has no filename
sourcepub fn basename<S: Into<String>>(self, basename: S) -> Self
pub fn basename<S: Into<String>>(self, basename: S) -> Self
The specified String is used as the basename of the log file name, instead of the program name. Using a file separator within the argument is discouraged.
sourcepub fn o_basename<S: Into<String>>(self, o_basename: Option<S>) -> Self
pub fn o_basename<S: Into<String>>(self, o_basename: Option<S>) -> Self
The specified String is used as the basename of the log file,
instead of the program name, which is used when None
is given.
sourcepub fn directory<P: Into<PathBuf>>(self, directory: P) -> Self
pub fn directory<P: Into<PathBuf>>(self, directory: P) -> Self
Specifies a folder for the log files.
If the specified folder does not exist, it will be created. By default, the log files are created in the folder where the program was started.
sourcepub fn o_directory<P: Into<PathBuf>>(self, directory: Option<P>) -> Self
pub fn o_directory<P: Into<PathBuf>>(self, directory: Option<P>) -> Self
Specifies a folder for the log files.
If the specified folder does not exist, it will be created. With None, the log files are created in the folder where the program was started.
sourcepub fn discriminant<S: Into<String>>(self, discriminant: S) -> Self
pub fn discriminant<S: Into<String>>(self, discriminant: S) -> Self
The specified String is added to the log file name.
sourcepub fn o_discriminant<S: Into<String>>(self, o_discriminant: Option<S>) -> Self
pub fn o_discriminant<S: Into<String>>(self, o_discriminant: Option<S>) -> Self
The specified String is added to the log file name.
sourcepub fn suffix<S: Into<String>>(self, suffix: S) -> Self
pub fn suffix<S: Into<String>>(self, suffix: S) -> Self
Specifies a suffix for the log files.
Equivalent to o_suffix(Some(suffix))
.
sourcepub fn o_suffix<S: Into<String>>(self, o_suffix: Option<S>) -> Self
pub fn o_suffix<S: Into<String>>(self, o_suffix: Option<S>) -> Self
Specifies a suffix for the log files, or supresses the use of a suffix completely.
The default suffix is “log”.
sourcepub fn suppress_timestamp(self) -> Self
pub fn suppress_timestamp(self) -> Self
Makes the logger not include a timestamp into the names of the log files
Equivalent to use_timestamp(false)
.
sourcepub fn use_timestamp(self, use_timestamp: bool) -> Self
pub fn use_timestamp(self, use_timestamp: bool) -> Self
Defines if a timestamp should be included into the names of the log files.
The default behavior depends on the usage:
- without rotation, a timestamp is by default included into the name
- with rotation, the timestamp is by default suppressed
sourcepub fn as_pathbuf(&self, o_infix: Option<&str>) -> PathBuf
pub fn as_pathbuf(&self, o_infix: Option<&str>) -> PathBuf
Creates a PathBuf
to the described log file.
It is composed like this:
<directory>/<basename>_<discr>_<timestamp><infix>.<suffix>