pub struct RotatingFileSinkBuilder<ArgBP, ArgRP> { /* private fields */ }
Expand description

The builder of RotatingFileSink.

Note

The generics here are designed to check for required fields at compile time, users should not specify them manually and/or depend on them. If the generic concrete types or the number of generic types are changed in the future, it may not be considered as a breaking change.

Examples

  • Building a RotatingFileSink.

    use spdlog::sink::{RotatingFileSink, RotationPolicy};
    
    let sink: RotatingFileSink = RotatingFileSink::builder()
        .base_path("/path/to/base_log_file") // required
        .rotation_policy(RotationPolicy::Hourly) // required
        // .max_files(100) // optional, defaults to `0` for no limit
        // .rotate_on_open(true) // optional, defaults to `false`
        .build()?;
  • If any required parameters are missing, a compile-time error will be raised.

    use spdlog::sink::{RotatingFileSink, RotationPolicy};
    
    let sink: RotatingFileSink = RotatingFileSink::builder()
        // .base_path("/path/to/base_log_file") // required
        .rotation_policy(RotationPolicy::Hourly) // required
        .max_files(100) // optional, defaults to `0` for no limit
        .rotate_on_open(true) // optional, defaults to `false`
        .build()?;
    use spdlog::sink::{RotatingFileSink, RotationPolicy};
    
    let sink: RotatingFileSink = RotatingFileSink::builder()
        .base_path("/path/to/base_log_file") // required
        // .rotation_policy(RotationPolicy::Hourly) // required
        .max_files(100) // optional, defaults to `0` for no limit
        .rotate_on_open(true) // optional, defaults to `false`
        .build()?;

Implementations

Specifies the base path of the log file.

The path needs to be suffixed with an extension, if you expect the rotated eventual file names to contain the extension.

If there is an extension, the different rotation policies will insert relevant information in the front of the extension. If there is not an extension, it will be appended to the end.

Supposes the given base path is /path/to/base_file.log, the eventual file names may look like the following:

  • /path/to/base_file_1.log
  • /path/to/base_file_2.log
  • /path/to/base_file_2022-03-23.log
  • /path/to/base_file_2022-03-24.log
  • /path/to/base_file_2022-03-23_03.log
  • /path/to/base_file_2022-03-23_04.log

This parameter is required.

Specifies the rotation policy.

This parameter is required.

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.

This parameter is optional, and defaults to 0.

Specifies whether to rotate files once when constructing RotatingFileSink.

For the RotationPolicy::Daily and RotationPolicy::Hourly 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.

This parameter is optional, and defaults to false.

Specifies a log level filter.

This parameter is optional, and defaults to LevelFilter::All.

Specifies a formatter.

This parameter is optional, and defaults to FullFormatter.

Specifies an error handler.

This parameter is optional, and defaults no handler, see Sink::set_error_handler for details.

Builds a RotatingFileSink.

Errors

If the argument rotation_policy is invalid, or an error occurs opening the file, Error::CreateDirectory or Error::OpenFile will be returned.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.