class

SimpLog::FileBackend

Inherits Log::IOBackend < Log::Backend < Reference < Object

Provides a Log::Backend that is backed with a log file that supports automatic rotation, compression, and purging at specified durations

Constants

DATETIME_FORMAT = "%Y%m%d%H%M%S%3N"

Datetime pattern used to suffix rotated file names

DEFAULT_COMPRESS_AFTER = 7.days

Default compress duration: logs will be compress after 1 week

DEFAULT_DISPATCH_MODE = ::Log::DispatchMode::Async

Default Log::DispatchMode

DEFAULT_GZIP_EXTENSION = ".gz"

Default file extension used for gzip compressed log files

DEFAULT_ROTATE_AT = 1.day

Default rotation duration: logs will be rotated after 1 day

Constructors

new(filename : String, *, formatter : Log::Formatter = ::Log::ShortFormat, dispatcher : Log::Dispatcher::Spec = DEFAULT_DISPATCH_MODE)

Creates a new LogFileBackend, filename should use .log extension for log retention to work correctly and ideally use a dedicated directory

Source
new(*, formatter : Log::Formatter = ::Log::ShortFormat, dispatcher : Log::Dispatcher::Spec = DEFAULT_DISPATCH_MODE)

Creates a new LogFileBackend with a log filename inferred from the executable filename

Source

Instance methods

close

Closes underlying resources used by this backend including the log file

Source
compress_after

File age at which log files will be gzip compressed

Source
compress_after=(compress_after : Time::Span)

File age at which log files will be gzip compressed

Source
delete_after

File age at which log files will be purged, if not set logs will be retained forever by default

Source
delete_after=(delete_after : Time::Span | Nil)

File age at which log files will be purged, if not set logs will be retained forever by default

Source
filename
Source
format(entry : Log::Entry) : Nil

Emits the entry to the log file, using the #formatter to convert

Source
next_rotation_at

When the next log file rotation is scheduled to occur

Source
rotate_at

File age at which the current log file will be rotated

Source
rotate_at=(rotate_at : Time::Span) : Nil

Sets the age at which the log file will be rotated

Source
write(entry : Log::Entry) : Nil

Writes an entry to the log file, first rotating the log file if required

Source