class SimpLog::FileBackend

Overview

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

Defined in:

simplog.cr

Constant Summary

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

Instance Method Summary

Constructor Detail

def self.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


[View source]
def self.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


[View source]

Instance Method Detail

def close : Nil #

Closes underlying resources used by this backend including the log file


[View source]
def compress_after : Time::Span #

File age at which log files will be gzip compressed


[View source]
def compress_after=(compress_after : Time::Span) #

File age at which log files will be gzip compressed


[View source]
def delete_after : Time::Span | Nil #

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


[View source]
def 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


[View source]
def filename : String #

[View source]
def format(entry : Log::Entry) : Nil #

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


[View source]
def next_rotation_at : Time #

When the next log file rotation is scheduled to occur


[View source]
def rotate_at : Time::Span #

File age at which the current log file will be rotated


[View source]
def rotate_at=(rotate_at : Time::Span) : Nil #

Sets the age at which the log file will be rotated


[View source]
def write(entry : Log::Entry) : Nil #

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


[View source]