birch/handler/file
File handler for log output with rotation support.
Writes log messages to files with configurable rotation strategies.
Types
Rotation strategy for log files.
pub type Rotation {
NoRotation
SizeRotation(max_bytes: Int, max_files: Int)
SizeRotationCompressed(
max_bytes: Int,
max_files: Int,
compress: Bool,
)
TimeRotation(interval: TimeInterval, max_files: Int)
CombinedRotation(
max_bytes: Int,
interval: TimeInterval,
max_files: Int,
)
}
Constructors
-
NoRotationNo rotation - file grows indefinitely
-
SizeRotation(max_bytes: Int, max_files: Int)Rotate when file exceeds max_bytes, keep up to max_files old files
-
SizeRotationCompressed( max_bytes: Int, max_files: Int, compress: Bool, )Rotate when file exceeds max_bytes, keep up to max_files old files, with optional gzip compression of rotated files
-
TimeRotation(interval: TimeInterval, max_files: Int)Rotate based on time interval, keep up to max_files old files
-
CombinedRotation( max_bytes: Int, interval: TimeInterval, max_files: Int, )Rotate on size OR time, whichever comes first
Time interval for time-based rotation.
pub type TimeInterval {
Hourly
Daily
}
Constructors
-
HourlyRotate every hour
-
DailyRotate daily at midnight
Values
pub fn format_rotation_timestamp(
interval: TimeInterval,
) -> String
Format a rotation timestamp based on the interval.
- Hourly: “2024-12-26T14” (includes hour)
- Daily: “2024-12-26” (date only)
pub fn handler(config: FileConfig) -> handler.Handler
Create a file handler with the given configuration. Uses human-readable format by default.
pub fn handler_with_formatter(
config: FileConfig,
format: fn(record.LogRecord) -> String,
) -> handler.Handler
Create a file handler with a custom formatter.
pub fn interval_to_hours(interval: TimeInterval) -> Int
Get the number of hours in a time interval.