pub struct RotatingFileSink { /* private fields */ }Expand description
A sink with a file as the target, split files according to the rotation policy.
A service program running for a long time may continuously write logs to a
single file, which makes the logs hard to view and manage.
RotatingFileSink is designed for this usage scenario. It automatically
splits logs into one or more files and can be configured to automatically
delete old files to save disk space. The operation of splitting logs into
multiple files and optionally deleting old files is called rotation. The
rotation policy determines when and how log files are created or
deleted.
§Examples
See ./examples directory.
Implementations§
Source§impl RotatingFileSink
impl RotatingFileSink
Sourcepub fn builder() -> RotatingFileSinkBuilder<(), ()>
pub fn builder() -> RotatingFileSinkBuilder<(), ()>
Gets a builder of RotatingFileSink with default parameters:
| Parameter | Default Value |
|---|---|
| level_filter | All |
| formatter | FullFormatter |
| error_handler | ErrorHandler::default() |
| base_path | must be specified |
| rotation_policy | must be specified |
| max_files | 0 |
| rotate_on_open | false |
| capacity | consistent with std |
Sourcepub fn new<P>(
base_path: P,
rotation_policy: RotationPolicy,
max_files: usize,
rotate_on_open: bool,
) -> Result<Self>
👎Deprecated since 0.3.0: it may be removed in the future, use RotatingFileSink::builder() instead
pub fn new<P>( base_path: P, rotation_policy: RotationPolicy, max_files: usize, rotate_on_open: bool, ) -> Result<Self>
RotatingFileSink::builder() insteadConstructs a RotatingFileSink.
The parameter max_files specifies the maximum number of files. If the
number of existing files reaches this parameter, the oldest file will be
deleted on the next rotation. Pass 0 for no limit.
The parameter rotate_on_open specifies whether to rotate files once
when constructing RotatingFileSink. For the RotationPolicy::Daily,
RotationPolicy::Hourly, and RotationPolicy::Period rotation
policies, it may truncate the contents of the existing file if the
parameter is true, since the file name is a time point and not an
index.
§Error
If an error occurs opening the file, Error::CreateDirectory or
Error::OpenFile will be returned.
§Panics
Panics if the parameter rotation_policy is invalid. See the
documentation of RotationPolicy for requirements.