Expand description
§LogRoller
LogRoller is a library for rolling over log files based on size or age. It supports various rotation strategies, time zones, and compression methods. LogRoller integrates seamlessly as an appender for the tracing crate, offering flexible log rotation with time zone support. Log rotation can be configured for either a fixed time zone or the local system time zone, ensuring logs align consistently with specific regional or user-defined time standards. This feature is particularly useful for applications that require organized logs by time, regardless of server location or daylight saving changes. LogRoller enables precise control over logging schedules, enhancing clarity and organization in log management across various time zones.
§Example
use {
logroller::{Compression, LogRollerBuilder, Rotation, RotationAge, TimeZone},
tracing_subscriber::util::SubscriberInitExt,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let appender = LogRollerBuilder::new("./logs", "tracing.log")
.rotation(Rotation::AgeBased(RotationAge::Minutely))
.max_keep_files(3)
.time_zone(TimeZone::Local) // Use system local time zone when rotating files
.compression(Compression::Gzip) // Compress rotated files with Gzip
.build()?;
let (non_blocking, _guard) = tracing_appender::non_blocking(appender);
tracing_subscriber::fmt()
.with_writer(non_blocking)
.with_ansi(false)
.with_target(false)
.with_file(true)
.with_line_number(true)
.finish()
.try_init()?;
tracing::info!("This is an info message");
tracing::warn!("This is a warning message");
tracing::error!("This is an error message");
Ok(())
}
Structs§
- LogRoller
- A log roller that rolls over logs based on size or age.
- LogRoller
Builder - Provides a fluent interface for configuring LogRoller instances.
Enums§
- Compression
- Specifies the compression algorithm to use for rotated log files.
- LogRoller
Error - Errors that can occur when using the log roller.
- Rotation
- Defines the strategy for when log files should be rotated.
- Rotation
Age - Specifies how frequently log files should be rotated when using age-based rotation.
- Rotation
Size - Defines size thresholds for rotating log files in various units.
- Time
Zone - Specifies the time zone to use for log file rotation and log file naming.