pub struct FileLogWriter { /* private fields */ }
Expand description

A configurable LogWriter implementation that writes to a file or a sequence of files.

See writers for usage guidance.

Implementations§

source§

impl FileLogWriter

source

pub fn builder(file_spec: FileSpec) -> FileLogWriterBuilder

Instantiates a builder for FileLogWriter.

source

pub fn format(&self) -> FormatFunction

Returns a reference to its configured output format function.

source

pub fn reset(&self, flwb: &FileLogWriterBuilder) -> Result<(), FlexiLoggerError>

Replaces parts of the configuration of the file log writer.

Note that the write mode and the format function cannot be reset and that the provided FileLogWriterBuilder must have the same values for these as the current FileLogWriter.

Errors

FlexiLoggerError::Reset if a reset was tried with a different write mode.

FlexiLoggerError::Io if the specified path doesn’t work.

FlexiLoggerError::OutputBadDirectory if the specified path is not a directory.

FlexiLoggerError::Poison if some mutex is poisoned.

source

pub fn config(&self) -> Result<FileLogWriterConfig, FlexiLoggerError>

Returns the current configuration of the file log writer

Errors

FlexiLoggerError::Poison if some mutex is poisoned.

source

pub fn reopen_outputfile(&self) -> Result<(), FlexiLoggerError>

Makes the FileLogWriter re-open the current log file.

FileLogWriter expects that nobody else modifies the file to which it writes, and offers capabilities to rotate, compress, and clean up log files.

However, if you use tools like linux’ logrotate to rename or delete the current output file, you need to inform the FileLogWriter about such actions by calling this method. Otherwise the FileLogWriter will not stop writing to the renamed or even deleted file!

Example

logrotate e.g. can be configured to send a SIGHUP signal to your program. You should handle SIGHUP in your program explicitly, e.g. using a crate like ctrlc, and call this function from the registered signal handler.

Errors

FlexiLoggerError::Poison if some mutex is poisoned.

source

pub fn rotate(&self) -> Result<(), FlexiLoggerError>

Trigger an extra log file rotation.

Does nothing if rotation is not configured.

Errors

FlexiLoggerError::Poison if some mutex is poisoned.

IO errors.

source

pub fn existing_log_files( &self, selector: &LogfileSelector ) -> Result<Vec<PathBuf>, FlexiLoggerError>

Returns the list of existing log files according to the current FileSpec.

The list includes the current log file and the compressed files, if they exist.

Errors

FlexiLoggerError::Poison if some mutex is poisoned.

Trait Implementations§

source§

impl Debug for FileLogWriter

source§

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

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

impl Drop for FileLogWriter

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl LogWriter for FileLogWriter

source§

fn write(&self, now: &mut DeferredNow, record: &Record<'_>) -> Result<()>

Writes out a log line. Read more
source§

fn flush(&self) -> Result<()>

Flushes any buffered records. Read more
source§

fn max_log_level(&self) -> LevelFilter

Provides the maximum log level that is to be written.
source§

fn reopen_output(&self) -> Result<(), FlexiLoggerError>

Re-open the current output, if meaningful. Read more
source§

fn rotate(&self) -> Result<(), FlexiLoggerError>

Rotate the current output, if meaningful. Read more
source§

fn shutdown(&self)

Cleanup open resources, if necessary.
source§

fn format(&mut self, format: FormatFunction)

Sets the format function. Read more

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