FileBuilder

Struct FileBuilder 

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

A builder to configure and create an File appender.

Implementations§

Source§

impl FileBuilder

Source

pub fn new(basedir: impl Into<PathBuf>, filename: impl Into<String>) -> Self

Create a new file appender builder.

Source

pub fn build(self) -> Result<File, Error>

Build the File appender.

§Errors

Return an error if either:

  • The log directory cannot be created.
  • The configured filename is empty.
Source

pub fn layout(self, layout: impl Into<Box<dyn Layout>>) -> Self

Set the layout for the logs.

Default to PlainTextLayout.

§Examples
use logforth_append_file::FileBuilder;
use logforth_layout_json::JsonLayout;

let builder = FileBuilder::new("my_service", "my_app");
builder.layout(JsonLayout::default());
Source

pub fn trap(self, trap: impl Into<Box<dyn Trap>>) -> Self

Set the trap for the file writer.

Default to [DefaultTrap].

§Examples
use logforth_append_file::FileBuilder;
use logforth_core::trap::DefaultTrap;

let builder = FileBuilder::new("my_service", "my_app");
builder.trap(DefaultTrap::default());
Source

pub fn rollover_minutely(self) -> Self

Set the rotation strategy to roll over log files minutely.

Source

pub fn rollover_hourly(self) -> Self

Set the rotation strategy to roll over log files hourly.

Source

pub fn rollover_daily(self) -> Self

Set the rotation strategy to roll over log files daily at 00:00 in the local time zone.

Source

pub fn rollover_size(self, n: NonZeroUsize) -> Self

Set the rotation strategy to roll over log files if the current log file exceeds the given size.

If any time-based rotation strategy is set, the size-based rotation will be checked on the current log file after the time-based rotation check.

Source

pub fn filename_suffix(self, suffix: impl Into<String>) -> Self

Set the filename suffix.

Source

pub fn max_log_files(self, n: NonZeroUsize) -> Self

Set the maximum number of log files to keep.

Trait Implementations§

Source§

impl Debug for FileBuilder

Source§

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

Formats the value using the given formatter. Read more

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.