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.

The filename is built from several partially optional components, using this pattern:

<basename>[_<discriminant>][_<date>_<time>][_infix][.<suffix>]

The default filename pattern without rotation uses the program name as basename, no discriminant, the timestamp of the program start, 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. 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 always starts with “_r”. For more details how its precise content can be influenced, see Naming.

Implementations§

source§

impl FileSpec

source

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.

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

source

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.

source

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.

source

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.

source

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.

source

pub fn discriminant<S: Into<String>>(self, discriminant: S) -> Self

The specified String is added to the log file name.

source

pub fn o_discriminant<S: Into<String>>(self, o_discriminant: Option<S>) -> Self

The specified String is added to the log file name.

source

pub fn suffix<S: Into<String>>(self, suffix: S) -> Self

Specifies a suffix for the log files.

Equivalent to o_suffix(Some(suffix)).

source

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”.

source

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).

source

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
source

pub fn as_pathbuf(&self, o_infix: Option<&str>) -> PathBuf

Derives a PathBuf from the spec and the given infix.

It is composed like this: <directory>/<basename>_<discr>_<timestamp><infix>.<suffix>

Trait Implementations§

source§

impl Clone for FileSpec

source§

fn clone(&self) -> FileSpec

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FileSpec

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for FileSpec

source§

fn default() -> Self

Describes a file in the current folder, using, as its filestem the program name followed by the current timestamp, and the suffix “.log”.

source§

impl PartialEq<FileSpec> for FileSpec

source§

fn eq(&self, other: &FileSpec) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for FileSpec

source§

impl StructuralEq for FileSpec

source§

impl StructuralPartialEq for FileSpec

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more