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
impl Manual
Sourcepub fn new<T, U>(file_prefix: T, file_suffix: U) -> Self
pub fn new<T, U>(file_prefix: T, file_suffix: U) -> Self
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();
Sourcepub fn line_sep<T>(self, line_sep: T) -> Self
pub fn line_sep<T>(self, line_sep: T) -> Self
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");
Sourcepub fn utc_time(self) -> Self
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();
Sourcepub fn local_time(self) -> Self
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();