LogFileWriter

Struct LogFileWriter 

Source
pub struct LogFileWriter {
    pub max_keep_age: Option<Duration>,
    pub max_keep_bytes: u64,
    pub max_write_age: Duration,
    pub max_write_bytes: u64,
    pub path_prefix: PathBuf,
}

Fields§

§max_keep_age: Option<Duration>§max_keep_bytes: u64§max_write_age: Duration§max_write_bytes: u64§path_prefix: PathBuf

Implementations§

Source§

impl LogFileWriter

Source

pub fn new_builder( path_prefix: impl Into<PathBuf>, max_keep_bytes: u64, ) -> LogFileWriter

Creates a new struct to write log files. It writes files with names that start with path_prefix.

DATA LOSS WARNING: Automatically deletes files that match path_prefix so the total size of the files is max_keep_bytes. Deletes the oldest files.

§Panics

Panics when path_prefix does not end with a filename part.

§Example
use std::path::PathBuf;
use servlin::log::LogFileWriter;
let writer = LogFileWriter::new_builder(
    PathBuf::from("/var/log/server.log"),
    100 * 1024 * 1024,
).start_writer_thread();
Source

pub fn with_max_keep_age(self, duration: Duration) -> Self

Configures the struct to continuously delete files that match path_prefix and are older than max_keep_age.

Defaults to 24 hours.

§Panics

Panics when duration is less than 1 minute.

Source

pub fn with_max_write_age(self, duration: Duration) -> Self

Configures the struct to close the current file and create a new file whenever the current file is older than duration.

Defaults to 10 MiB.

§Panics

Panics when duration is less than 1 second.

Source

pub fn with_max_write_bytes(self, len: u64) -> Self

Configures the struct to write len bytes or less to each log file before switching to a new one.

§Panics

Panics when len is less than 64 KiB.

Source

pub fn start_writer_thread(self) -> Result<SyncSender<LogEvent>, Error>

Creates the first log file and starts the log file writer thread.

§Errors

Returns Err when it fails to create the first log file.

Auto Trait Implementations§

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