Trait file_rotate::suffix::SuffixScheme

source ·
pub trait SuffixScheme {
    type Repr: Representation;

    // Required methods
    fn rotate_file(
        &mut self,
        basepath: &Path,
        newest_suffix: Option<&Self::Repr>,
        suffix: &Option<Self::Repr>
    ) -> Result<Self::Repr>;
    fn parse(&self, suffix: &str) -> Option<Self::Repr>;
    fn too_old(&self, suffix: &Self::Repr, file_number: usize) -> bool;

    // Provided method
    fn scan_suffixes(&self, basepath: &Path) -> BTreeSet<SuffixInfo<Self::Repr>> { ... }
}
Expand description

How to move files: How to rename, when to delete.

Required Associated Types§

source

type Repr: Representation

The representation of suffixes that this suffix scheme uses. E.g. if the suffix is a number, you can use usize.

Required Methods§

source

fn rotate_file( &mut self, basepath: &Path, newest_suffix: Option<&Self::Repr>, suffix: &Option<Self::Repr> ) -> Result<Self::Repr>

file-rotate calls this function when the file at suffix needs to be rotated, and moves the log file accordingly. Thus, this function should not move any files itself.

If suffix is None, it means it’s the main log file (with path equal to just basepath) that is being rotated.

Returns the target suffix that the log file should be moved to. If the target suffix already exists, rotate_file is called again with suffix set to the target suffix. Thus it cascades files by default, and if this is not desired, it’s up to rotate_file to return a suffix that does not already exist on disk.

newest_suffix is provided just in case it’s useful (depending on the particular suffix scheme, it’s not always useful)

source

fn parse(&self, suffix: &str) -> Option<Self::Repr>

Parse suffix from string.

source

fn too_old(&self, suffix: &Self::Repr, file_number: usize) -> bool

Whether either the suffix or the chronological file number indicates that the file is old and should be deleted, depending of course on the file limit. file_number starts at 0 for the most recent suffix.

Provided Methods§

source

fn scan_suffixes(&self, basepath: &Path) -> BTreeSet<SuffixInfo<Self::Repr>>

Find all files in the basepath.parent() directory that has path equal to basepath + a valid suffix. Return sorted collection - sorted from most recent to oldest based on the Ord implementation of Self::Repr.

Implementors§