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_AT = 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(formatter : Log::Formatter = ::Log::ShortFormat) #

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


[View source]
def self.new(filename : String, formatter : Log::Formatter = ::Log::ShortFormat) #

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


[View source]

Instance Method Detail

def compress_at : Time::Span #

File age at which log files will be gzip compressed


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

File age at which log files will be gzip compressed


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

Emits the entry to the current file. It uses the #formatter to convert.


[View source]
def next_rotation_at : Time #

When the next log file rotation is scheduled to occur


[View source]
def retention : 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 retention=(retention : 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 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 rotating the log file if required


[View source]