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: PathBufImplementations§
Source§impl LogFileWriter
impl LogFileWriter
Sourcepub fn new_builder(
path_prefix: impl Into<PathBuf>,
max_keep_bytes: u64,
) -> LogFileWriter
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();Sourcepub fn with_max_keep_age(self, duration: Duration) -> Self
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.
Sourcepub fn with_max_write_age(self, duration: Duration) -> Self
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.
Sourcepub fn with_max_write_bytes(self, len: u64) -> Self
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.
Sourcepub fn start_writer_thread(self) -> Result<SyncSender<LogEvent>, Error>
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.