Struct custom_utils::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>(p: P) -> Result<FileSpec, FlexiLoggerError>where
P: Into<PathBuf>,
pub fn try_from<P>(p: P) -> Result<FileSpec, FlexiLoggerError>where P: Into<PathBuf>,
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>(self, basename: S) -> FileSpecwhere
S: Into<String>,
pub fn basename<S>(self, basename: S) -> FileSpecwhere S: Into<String>,
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>(self, o_basename: Option<S>) -> FileSpecwhere
S: Into<String>,
pub fn o_basename<S>(self, o_basename: Option<S>) -> FileSpecwhere S: Into<String>,
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>(self, directory: P) -> FileSpecwhere
P: Into<PathBuf>,
pub fn directory<P>(self, directory: P) -> FileSpecwhere P: Into<PathBuf>,
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>(self, directory: Option<P>) -> FileSpecwhere
P: Into<PathBuf>,
pub fn o_directory<P>(self, directory: Option<P>) -> FileSpecwhere P: Into<PathBuf>,
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>(self, discriminant: S) -> FileSpecwhere
S: Into<String>,
pub fn discriminant<S>(self, discriminant: S) -> FileSpecwhere S: Into<String>,
The specified String is added to the log file name.
sourcepub fn o_discriminant<S>(self, o_discriminant: Option<S>) -> FileSpecwhere
S: Into<String>,
pub fn o_discriminant<S>(self, o_discriminant: Option<S>) -> FileSpecwhere S: Into<String>,
The specified String is added to the log file name.
sourcepub fn suffix<S>(self, suffix: S) -> FileSpecwhere
S: Into<String>,
pub fn suffix<S>(self, suffix: S) -> FileSpecwhere S: Into<String>,
Specifies a suffix for the log files.
Equivalent to o_suffix(Some(suffix))
.
sourcepub fn o_suffix<S>(self, o_suffix: Option<S>) -> FileSpecwhere
S: Into<String>,
pub fn o_suffix<S>(self, o_suffix: Option<S>) -> FileSpecwhere S: Into<String>,
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) -> FileSpec
pub fn suppress_timestamp(self) -> FileSpec
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) -> FileSpec
pub fn use_timestamp(self, use_timestamp: bool) -> FileSpec
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>