pub struct FileSpec { /* private fields */ }
Expand description
Builder object for specifying the name and path of the log output file.
The filename is built from several partially components, using this pattern:
<filename> = [<basename>][_][<discriminant>][_][<starttime>][_][<infix>][.<suffix>]
-
[<basename>]
: This is by default the program’s name, but can be set to a different value or suppressed at all. -
[_]
: Consecutive name parts are separated by an underscore. No underscore is used at the beginning of the filename and directly before the suffix. -
[<discriminant>]
: some optional name part that allows further differentiations. -
[<starttime>]
: denotes the point in time when the program was started, if used. -
[infix]
: used with rotation to differentiate consecutive files.
Without rotation, the default filename pattern uses the program name as basename,
no discriminant, the timestamp of the program start
(printed in the format “YYYY-MM-DD_hh-mm-ss”),
and the suffix .log
, e.g.
myprog_2015-07-08_10-44-11.log
.
This ensures that with every program start a new trace file is written that can easily be associated with a concrete program run.
When the timestamp is suppressed with FileSpec::suppress_timestamp
,
you get a fixed output file name.
It is then worth considering whether a new program start should discard
the content of an already existing outputfile or if it should append its new content to it
(see Logger::append
).
With rotation, the timestamp is by default suppressed and instead the infix is used.
The infix starts always with “r”.
For more details how its precise content can be influenced, see Naming
.
Implementations§
Source§impl FileSpec
impl FileSpec
Sourcepub fn try_from<P>(p: P) -> Result<FileSpec, FlexiLoggerError>
pub fn try_from<P>(p: P) -> Result<FileSpec, 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.
assert_eq!(
FileSpec::default()
.directory("/a/b/c")
.basename("foo")
.suppress_timestamp()
.suffix("bar"),
FileSpec::try_from("/a/b/c/foo.bar").unwrap()
);
§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 suppress_basename(self) -> FileSpec
pub fn suppress_basename(self) -> FileSpec
Makes the logger not include a basename into the names of the log files
Equivalent to basename("")
.
Sourcepub fn basename<S>(self, basename: S) -> FileSpec
pub fn basename<S>(self, basename: S) -> FileSpec
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>) -> FileSpec
pub fn o_basename<S>(self, o_basename: Option<S>) -> FileSpec
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) -> FileSpec
pub fn directory<P>(self, directory: P) -> FileSpec
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>) -> FileSpec
pub fn o_directory<P>(self, directory: Option<P>) -> FileSpec
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) -> FileSpec
pub fn discriminant<S>(self, discriminant: S) -> FileSpec
The specified String is added to the log file name.
Sourcepub fn o_discriminant<S>(self, o_discriminant: Option<S>) -> FileSpec
pub fn o_discriminant<S>(self, o_discriminant: Option<S>) -> FileSpec
The specified String is added to the log file name.
Sourcepub fn suffix<S>(self, suffix: S) -> FileSpec
pub fn suffix<S>(self, suffix: S) -> FileSpec
Specifies a suffix for the log files.
Equivalent to o_suffix(Some(suffix))
.
Sourcepub fn o_suffix<S>(self, o_suffix: Option<S>) -> FileSpec
pub fn o_suffix<S>(self, o_suffix: Option<S>) -> FileSpec
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 the start time 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 the start time 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
Derives a PathBuf
from the spec and the given infix.
Trait Implementations§
impl Eq for FileSpec
impl StructuralPartialEq for FileSpec
Auto Trait Implementations§
impl Freeze for FileSpec
impl RefUnwindSafe for FileSpec
impl Send for FileSpec
impl Sync for FileSpec
impl Unpin for FileSpec
impl UnwindSafe for FileSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.