fern

Struct Manual

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

This is used to generate log file suffixed based on date, hour, and minute.

The log file will be rotated manually when builder::rotate() is called.

Implementations§

Source§

impl Manual

Source

pub fn new<T, U>(file_prefix: T, file_suffix: U) -> Self
where T: AsRef<Path>, U: Into<Cow<'static, str>>,

Create new manual file logger with the given file prefix and strftime-based suffix pattern.

On initialization, fern will create a file with the suffix formatted with the current time (either utc or local, see below). Each time a record is logged, the format is checked against the current time, and if the time has changed, the old file is closed and a new one opened.

file_suffix will be interpreted as an strftime format. See chrono::format::strftime for more information.

file_prefix may be a full file path, and will be prepended to the suffix to create the final file.

Note that no separator will be placed in between file_name and file_suffix_pattern. So if you call Manual::new("hello", "%Y"), the result will be a filepath hello2019.

By default, this will use local time. For UTC time instead, use the .utc_time() method after creating.

By default, this will use \n as a line separator. For a custom separator, use the .line_sep method after creating.

§Examples

Containing the date (year, month and day):

// logs/2019-10-23-my-program.log
let log = fern::Manual::new("logs/", "%Y-%m-%d-my-program.log");

// program.log.23102019
let log = fern::Manual::new("my-program.log.", "%d%m%Y");

Containing the hour:

// logs/2019-10-23 13 my-program.log
let log = fern::Manual::new("logs/", "%Y-%m-%d %H my-program.log");

// program.log.2310201913
let log = fern::Manual::new("my-program.log.", "%d%m%Y%H");

Containing the minute:

// logs/2019-10-23 13 my-program.log
let log = fern::Manual::new("logs/", "%Y-%m-%d %H my-program.log");

// program.log.2310201913
let log = fern::Manual::new("my-program.log.", "%d%m%Y%H");

UNIX time, or seconds since 00:00 Jan 1st 1970:

// logs/1571822854-my-program.log
let log = fern::Manual::new("logs/", "%s-my-program.log");

// program.log.1571822854
let log = fern::Manual::new("my-program.log.", "%s");

Hourly, using UTC time:

// logs/2019-10-23 23 my-program.log
let log = fern::Manual::new("logs/", "%Y-%m-%d %H my-program.log").utc_time();

// program.log.2310201923
let log = fern::Manual::new("my-program.log.", "%d%m%Y%H").utc_time();
Source

pub fn line_sep<T>(self, line_sep: T) -> Self
where T: Into<Cow<'static, str>>,

Changes the line separator this logger will use.

The default line separator is \n.

§Examples

Using a windows line separator:

let log = fern::Manual::new("logs", "%s.log").line_sep("\r\n");
Source

pub fn utc_time(self) -> Self

Orients this log file suffix formatting to use UTC time.

The default is local time.

§Examples

This will use UTC time to determine the date:

// program.log.2310201923
let log = fern::Manual::new("my-program.log.", "%d%m%Y%H").utc_time();
Source

pub fn local_time(self) -> Self

Orients this log file suffix formatting to use local time.

This is the default option.

§Examples

This log file will use local time - the latter method call overrides the former.

// program.log.2310201923
let log = fern::Manual::new("my-program.log.", "%d%m%Y%H")
    .utc_time()
    .local_time();

Trait Implementations§

Source§

impl Clone for Manual

Source§

fn clone(&self) -> Manual

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Manual

Source§

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

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

impl From<Manual> for Output

Source§

fn from(config: Manual) -> Self

Create an output logger which defers to the given manual logger. Use configuration methods on Manual to set line separator and filename.

Auto Trait Implementations§

§

impl Freeze for Manual

§

impl RefUnwindSafe for Manual

§

impl Send for Manual

§

impl Sync for Manual

§

impl Unpin for Manual

§

impl UnwindSafe for Manual

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.