Agent::Driver(3pm) | User Contributed Perl Documentation | Agent::Driver(3pm) |
Log::Agent::Driver - ancestor class for all Log::Agent drivers
@Log::Agent::Driver::XXX::ISA = qw(Log::Agent::Driver);
The Log::Agent::Driver class is the root class from which all Log::Agent drivers inherit. It is a deferred class, meaning that it cannot be instantiated directly. All the deferred routines need to be implemented by its heirs to form a valid driver.
A deferred routine is a routine whose signature and semantics (pre and post conditions, formally) are specified, but not implemented. It allows specification of high-level processings in terms of them, thereby factorizing common code in the ancestors without loosing specialization benefits.
The following drivers are currently fully implemented:
You need not read this section if you're only using Log::Agent. However, if you wish to implement another driver, then you should probably read it a few times.
The following routines are deferred and therefore need to be defined by the heir:
The $channel name is just a string, and it is up to the driver to map that name to an output device using its own configuration information. The generic logxxx() routines use only "error", "output" or "debug" for channel names.
The $priority entry is assumed to have passed through the map_pri() routine, which by default returns an empty string (only the Log::Agent::Driver::Syslog driver needs a priority, for now). Ignore if you don't need that, or redefine map_pri().
The $logstring may not really be a plain string. It can actually be a Log::Agent::Message object with an overloaded stringification routine, so the illusion should be complete.
Must return the prefixed string, either as a Log::Agent::Message object or as a plain string. This means you may use normal string operations on the $str variable and let the overloaded stringification perform its magic. Or you may return the $str parameter without modification.
There is no default implementation here because this is too driver-specific to choose one good default. And I like making things explicit sometimes.
The following routines are implemented in terms of write(), map_pri() and prefix_msg(). The default implementation may need to be redefined for performance or tuning reasons, but simply defining the deferred routines above should bring a reasonable behaviour.
As an example, here is the default logsay() implementation, which uses the emit() wrapper (see below):
sub logsay { my $self = shift; my ($str) = @_; $self->emit('output', 'notice', $str); }
Yes, we do show the gory details in a manpage, but inheriting from a class is not for the faint of heart, and requires getting acquainted with the implementation, most of the time.
The order is not alphabetical here but by increased level of severity (as expected, anyway):
The following routines have a default implementation but may be redefined for specific drivers:
write($channel, $self->priority($prio), $self->prefix_msg($str))
using dynamic binding.
The following routine is frozen. There is no way in Perl to freeze a routine, i.e. to explicitly forbid any redefinition, so this is an informal notification:
It derives a logging level from the $priority given and then returns the result of:
map_pri($priority, $level);
Therefore, only map_pri() should be redefined.
Finally, the following initialization routine is provided: to record the
Originally written by Raphael Manfredi <Raphael_Manfredi@pobox.com>, currently maintained by Mark Rogaski <mrogaski@cpan.org>.
Copyright (C) 1999 Raphael Manfredi. Copyright (C) 2002 Mark Rogaski; all rights reserved.
See Log::Agent(3) or the README file included with the distribution for license information.
Log::Agent(3), Log::Agent::Driver::Default(3), Log::Agent::Driver::File(3), Log::Agent::Driver::Fork(3), Log::Agent::Driver::Silent(3), Log::Agent::Driver::Syslog(3), Carp::Datum(3).
2022-10-15 | perl v5.34.0 |