Struct LogFileInitializer

Source
pub struct LogFileInitializer<'a, P>
where P: AsRef<Path>,
{ pub directory: P, pub filename: &'a str, pub max_n_old_files: usize, pub preferred_max_file_size_mib: u64, }
Expand description

The initializer of the log file. See Self::init.

Fields§

§directory: P

The directory where the log files will be placed in.

The directory and its parent directories will be recursively created if they don’t already exist while calling init (equivalent to mkdir -p).

The directory should be used exclusively for the log files. Other files in the directory will slow down the process of counting existing old files and finding the oldest one to delete if max_n_old_files is exceeded.

§filename: &'a str

The file name of the uncompressed log file that will be opened and returned (directory/filename).

§max_n_old_files: usize

The maximum number of old (compressed) log files.

The value 0 leads to directly returning the file in append mode. The value of preferred_max_file_size_mib will be ignored in that case.

You shouldn’t manually set max_n_old_files to 0. If you don’t want rolling, just create the directory and the file manually and open the file in append mode instead of having this library as a dependency. The value 0 is just supported as a fallback in case the user of your program wants to deactivate rolling.

§preferred_max_file_size_mib: u64

The preferred maximum size of the uncompressed log file directory/filename in MiB.

It is called the preferred maximum file size because this file size can be exceeded before the next initialization. If the file size exceeds the preferred maximum, rolling will only happen if it was not already done on the same day (in UTC).

Implementations§

Source§

impl<'a, P> LogFileInitializer<'a, P>
where P: AsRef<Path>,

Source

pub fn init(self) -> Result<File>

Return a file at directory/filename for appending new logs.

Rolling will be applied to the file directory/file if all the following conditions are true:

In the case of rolling, the file will be compressed with GZIP to directory/filename-YYYYMMDD.gz with today’s date (in UTC).

If rolling was applied and the number of old files exceeds max_n_old_files, the oldest file will be deleted.

§Example
let log_file = LogFileInitializer {
  directory: "logs",
  filename: "test",
  max_n_old_files: 2,
  preferred_max_file_size_mib: 1,
}.init()?;
§Compatibility

Only UTF8 paths are supported.

Auto Trait Implementations§

§

impl<'a, P> Freeze for LogFileInitializer<'a, P>
where P: Freeze,

§

impl<'a, P> RefUnwindSafe for LogFileInitializer<'a, P>
where P: RefUnwindSafe,

§

impl<'a, P> Send for LogFileInitializer<'a, P>
where P: Send,

§

impl<'a, P> Sync for LogFileInitializer<'a, P>
where P: Sync,

§

impl<'a, P> Unpin for LogFileInitializer<'a, P>
where P: Unpin,

§

impl<'a, P> UnwindSafe for LogFileInitializer<'a, P>
where P: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.