Struct FileHandler

Source
pub struct FileHandler { /* private fields */ }
Expand description

A handler that writes log records to a file.

Implementations§

Source§

impl FileHandler

Source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>

Creates a new file handler that writes to the specified file.

§Arguments
  • path - The path to the log file
  • level - The minimum log level to handle
§Returns

A new FileHandler instance

§Errors

Returns an error if the file cannot be opened or created

Source

pub fn close(&mut self)

Closes the file handle if it’s open.

Source

pub fn with_colors(self, use_colors: bool) -> Self

Sets whether to use colors in the output.

Source

pub fn with_pattern(self, pattern: impl Into<String>) -> Self

Sets the format pattern to use.

Source

pub fn path(&self) -> &str

Returns the path to the log file.

Source

pub fn with_rotation(self, max_size: u64) -> Self

Sets the maximum file size before rotation

Source

pub fn with_retention(self, retention: usize) -> Self

Sets the number of old files to keep

Trait Implementations§

Source§

impl Debug for FileHandler

Source§

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

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

impl Handler for FileHandler

Source§

fn level(&self) -> LogLevel

Get the current log level
Source§

fn set_level(&mut self, level: LogLevel)

Set the log level
Source§

fn enabled(&self) -> bool

Check if the handler is enabled
Source§

fn set_enabled(&mut self, enabled: bool)

Enable or disable the handler
Source§

fn formatter(&self) -> &Formatter

Get the formatter
Source§

fn set_formatter(&mut self, formatter: Formatter)

Set the formatter
Source§

fn handle(&mut self, record: &Record) -> bool

Handle a log record

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