NAME
Log::Abstraction::Backend - base class of the Log::Abstraction backends
VERSION
0.40
DESCRIPTION
For use by Log::Abstraction only. Log::Abstraction->new() builds one object of a Log::Abstraction::Backend::* class for each place a message goes to (a file, an array, syslog ...), and each message is passed to every one of them. The configuration given to new() is not changed.
The backends are:
Log::Abstraction::Backend::Array array, or logger => \@array
Log::Abstraction::Backend::Code logger => \&code
Log::Abstraction::Backend::Fd fd
Log::Abstraction::Backend::File file, or logger => $path
Log::Abstraction::Backend::Journald journald
Log::Abstraction::Backend::LogAny log_any, or a Log::Any logger
Log::Abstraction::Backend::LogDispatch log_dispatch, or a Log::Dispatch object
Log::Abstraction::Backend::Object any other object as the logger
Log::Abstraction::Backend::Sendmail sendmail
Log::Abstraction::Backend::Syslog syslog
METHODS
new
my $backend = Log::Abstraction::Backend::File->new(
file => $path,
level => 4, # numeric threshold, or undef for none
format => $format, # or undef
);
Stores its arguments. They have already been checked by Log::Abstraction->new(); level is a syslog number (0-7).
API SPECIFICATION
Input
{
level => { type => 'integer', min => 0, max => 7, optional => 1 },
format => { type => 'string', min => 1, optional => 1 },
# and the destination, under the backend's own key (file, fd,
# array, sendmail ...)
}
Output
{ type => 'object', isa => 'Log::Abstraction::Backend' }
wants
next unless $backend->wants($event);
True if the backend has no level of its own, or the message is at that level or more severe.
API SPECIFICATION
Input
{ event => { type => 'hashref', schema => { priority => { type => 'integer', min => 0, max => 7 } } } }
Output
{ type => 'boolean' }
text
my $message = $backend->text($event, $event->{text});
The message formatted with the backend's own format, if it has one, otherwise the default given.
API SPECIFICATION
Input
{
event => { type => 'hashref', schema => { render => { type => 'coderef' } } },
default => { type => 'string' },
}
Output
{ type => 'string' }
emit
$backend->emit($logger, $event);
Sends a message, which has passed the logger's level, to the backend. $logger is the Log::Abstraction object. $event is a hash reference built by Log::Abstraction for each message:
level the level name, e.g. 'warn'
priority its syslog number (0-7)
message the message, its parts joined and redacted
parts the message's parts (an array reference)
fields the structured fields (a hash reference), or undef
fields_text the fields as key=value text, or undef
text the message with fields_text appended
entry the history entry (a list, as an array reference)
class, file, line, ctx for CODE references
render format a line: $event->{render}->($format), undef for
the logger's format
write write a line to a path (which it checks) or a handle:
$event->{write}->($target, $line)
send_email, hold_email send or keep for later an email:
$event->{send_email}->(\%sendmail, $body)
The closures are how a backend uses Log::Abstraction's private methods. Subclasses must override this.
API SPECIFICATION
Input
{
logger => { type => 'object', isa => 'Log::Abstraction' },
event => { type => 'hashref' }, # the keys above
}
Output
None. The base class's emit() croaks "<class>: emit() is not
implemented"; a subclass's sends the message. A failed delivery is
carped, not fatal; a configuration error (e.g. an invalid sendmail
host) still croaks.
AUTHOR
Nigel Horne njh@nigelhorne.com
SEE ALSO
COPYRIGHT AND LICENSE
Copyright (C) 2025-2026 Nigel Horne
Usage is subject to the GPL2 licence terms. If you use it, please let me know.