[−][src]Struct fern::DateBased
This is used to generate log file suffixed based on date, hour, and minute.
The log file will be rotated automatically when the date changes.
Methods
impl DateBased
[src]
pub fn new<T, U>(file_prefix: T, file_suffix: U) -> Self where
T: AsRef<Path>,
U: Into<Cow<'static, str>>,
[src]
T: AsRef<Path>,
U: Into<Cow<'static, str>>,
Create new date-based 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 DateBased::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::DateBased::new("logs/", "%Y-%m-%d-my-program.log"); // program.log.23102019 let log = fern::DateBased::new("my-program.log.", "%d%m%Y");
Containing the hour:
// logs/2019-10-23 13 my-program.log let log = fern::DateBased::new("logs/", "%Y-%m-%d %H my-program.log"); // program.log.2310201913 let log = fern::DateBased::new("my-program.log.", "%d%m%Y%H");
Containing the minute:
// logs/2019-10-23 13 my-program.log let log = fern::DateBased::new("logs/", "%Y-%m-%d %H my-program.log"); // program.log.2310201913 let log = fern::DateBased::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::DateBased::new("logs/", "%s-my-program.log"); // program.log.1571822854 let log = fern::DateBased::new("my-program.log.", "%s");
Hourly, using UTC time:
// logs/2019-10-23 23 my-program.log let log = fern::DateBased::new("logs/", "%Y-%m-%d %H my-program.log").utc_time(); // program.log.2310201923 let log = fern::DateBased::new("my-program.log.", "%d%m%Y%H").utc_time();
pub fn line_sep<T>(self, line_sep: T) -> Self where
T: Into<Cow<'static, str>>,
[src]
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::DateBased::new("logs", "%s.log").line_sep("\r\n");
pub fn utc_time(self) -> Self
[src]
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::DateBased::new("my-program.log.", "%d%m%Y%H").utc_time();
pub fn local_time(self) -> Self
[src]
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::DateBased::new("my-program.log.", "%d%m%Y%H") .utc_time() .local_time();
Trait Implementations
impl From<DateBased> for Output
[src]
fn from(config: DateBased) -> Self
[src]
Create an output logger which defers to the given date-based logger. Use configuration methods on DateBased to set line separator and filename.
impl Debug for DateBased
[src]
Auto Trait Implementations
impl Send for DateBased
impl Sync for DateBased
impl Unpin for DateBased
impl UnwindSafe for DateBased
impl RefUnwindSafe for DateBased
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,