Agent::Driver(3pm)
π Agent::Driver(3pm) β aka Log::Agent::Driver π
okay bestie, buckle UP β this is the manual page for Log::Agent::Driver, riding in the User Contributed Perl Documentation section of your friendly neighbourhood Agent::Driver(3pm) man suite. It's the ancestor class, the momager, the blueprint. πΈ
β¨ NAME β¨
Log::Agent::Driver β the ancestor class for ALL the Log::Agent drivers. Every single one. She's the origin story. π
β¨ SYNOPSIS β¨
@Log::Agent::Driver::XXX::ISA = qw(Log::Agent::Driver);
That's it. That's the whole synopsis. Short queen. π
β¨ DESCRIPTION β¨
So Log::Agent::Driver is the root class β the class at the very top of the family tree that every Log::Agent driver inherits from. But here's the tea: she's a deferred class, which means you literally cannot instantiate her directly. No Log::Agent::Driver->new for you. π«
Instead, all the deferred routines have to be implemented by her heirs (aka her subclasses) before anything counts as a valid driver. Think of it like a group project where she wrote the rubric and everyone else has to actually do the work. π
And what even is a deferred routine, you ask? It's a routine whose signature and semantics (the pre and post conditions, formally) are fully specified but not implemented. Why bother? Because it lets you specify high-level processings in terms of them, which factorizes common code up in the ancestors without losing the benefits of specialization. Iconic architecture behaviour, no cap. β¨
β¨ DRIVER LIST β¨
Here are the drivers that are currently fully implemented, bestie:
Log::Agent::Driver::Defaultβ the default driver, and she remaps to the simpleprint(),warn()anddie()Perl calls. Classic. Reliable. Ate. πLog::Agent::Driver::Fileβ this one redirects logs to files. And not just one file: each logging channel can go to its own dedicated file. Organized queen. πLog::Agent::Driver::Silentβ silences all thelogxxx()routines. She's giving β¨ nothing β¨ and that's the point.Log::Agent::Driver::Syslogβ redirects logs to thesyslogd(8)daemon, which then handles the dispatching to the various logfiles based on its own configuration. Delegation! Main character energy! π
β¨ INTERFACE β¨
ngl, if you're only using Log::Agent, you do NOT need to read this section. Skip it. Go live your life. π¦ But if you wanna implement another driver? Then bestie, you should probably read this a few times. Maybe a few more after that. fr fr.
The following routines are deferred, which means the heir has to define them:
channel_eq($chan1, $chan2)β returns true when both channels$chan1and$chan2send their output to the same place. Now, the goal here is not a 100% accurate comparison (which is basically impossible for theLog::Agent::Driver::Filedriver anyway, let's be real), but to reasonably detect similarities so we can avoid duplicating messages to the same output whenCarp::Datumis installed and activated. Vibes-based deduplication, and honestly? Valid.write($channel, $priority, $logstring)β emits the log entry held in$logstring, at priority$priority, through the specified$channelname. A trailing"\n"is to be added if needed, but the$logstringshould not already have one. π βοΈ- The
$channelname is just a string, and it's up to the driver to map that name to an output device using its own configuration info. The genericlogxxx()routines only ever use"error","output"or"debug"for channel names. - The
$priorityentry is assumed to have already passed through themap_pri()routine, which by default returns an empty string (only theLog::Agent::Driver::Syslogdriver needs a priority, for now). Ignore it if you don't need it, or redefinemap_pri(). - The
$logstringmay not really be a plain string, actually. It can be aLog::Agent::Messageobject with an overloaded stringification routine, so the illusion should be complete. πͺ
- The
makeβ this is the creation routine. Its signature varies for each driver, naturally. No two queens are the same. πprefix_msg($str)β prefixes the log message string (aLog::Agent::Messageobject) with driver-specific info, like the configured prefix, the PID of the process, etc...- Must return the prefixed string, either as a
Log::Agent::Messageobject or as a plain string. Which means you may use normal string operations on the$strvariable and let the overloaded stringification perform its magic. Or you may just return the$strparameter without modification. Your call. π«Ά - There is no default implementation here, because this is way too driver-specific to choose one good default. And sometimes the author just likes making things explicit. Respect.
- Must return the prefixed string, either as a
The following routines are implemented in terms of write(), map_pri() and prefix_msg(). The default implementation might need to be redefined for performance or tuning reasons, but simply defining the deferred routines above should bring a reasonable behaviour. Slay. β¨
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 it requires getting acquainted with the implementation most of the time. That's just how it is, bestie. π«
The order here is not alphabetical β it's by increased level of severity (as expected, anyway):
logwrite($channel, $priority, $level, $str)β logs a message to the given channel, at the specified priority/level, obtained through a call tomap_pri().logsay($str)β logs the message to the"output"channel, at the"notice"priority.logwarn($str)β logs a warning to the"error"channel at the"warning"priority.logxcarp($offset, $str)β logs a warning to the"error"channel at the"warning"priority, but from the perspective of the caller. An additional$offsetstack frames are skipped to find the caller (added to the hardwired fixed offset imposed by the overallLog::Agentarchitecture). Yeah, it's stack frames all the way down. π΅logerr($str)β logs an error to the"error"channel at the"error"priority.logdie($str)β logs a fatal error to the"error"channel at the"critical"priority, and then callsdie()with"$str\n"as argument. Dramatic exit, as she deserves. πlogxcroak($offset, $str)β logs a fatal error, from the perspective of the caller. The error goes to the"error"channel at the"critical"priority, and thenCarp::croak()is called with"$str\n"as argument. An additional$offsetstack frames are skipped to find the caller (added to the hardwired fixed offset imposed by the overallLog::Agentarchitecture).logconfess($str)β confesses a fatal error. The error is logged to the"error"channel at the"critical"priority, and thenCarp::confess()is called with"$str\n"as argument.logcluck($str)β emits a warning with a backtrace. The message is logged to the"error"channel at the"warning"priority.
The following routines have a default implementation, but they may be redefined for specific drivers:
emit($channel, $prio, $str)β this is a convenient wrapper that calls:
write($channel, $self->priority($prio), $self->prefix_msg($str))
using dynamic binding. Fancy. π
map_pri($priority, $level)β converts a("priority", level)tuple into a single priority token suitable foremit(). By default it returns an empty string, which is OK only whenemit()does not care! Read that again, bestie.
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. She's not locked, she's just spoken for. π
priority($priority)β returns the proper priority foremit()for each of the following strings:"critical","error","warning"and"notice", which are the hardwired priority strings, as documented above.- It derives a logging level from the
$prioritygiven, and then returns the result of:
- It derives a logging level from the
map_pri($priority, $level);
- Therefore, only
map_pri()should be redefined. Don't touch the rest, she's fine. π
Finally, the following initialization routine is provided: to record the...
_init($prefix, $penalty)β records the"prefix"attribute, as well as the Carp"penalty"(the amount of extra stack frames to skip). This should be called in the constructor of all the drivers. Every single one. No exceptions. π«Ά
β¨ AUTHORS β¨
Originally written by Raphael Manfredi <Raphael_Manfredi@pobox.com>, currently maintained by Mark Rogaski <mrogaski@cpan.org>. Legends, both of them. π
β¨ LICENSE β¨
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. π
β¨ SEE ALSO β¨
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).
and that's the whole page, bestie, you ate it UP πβ¨πΈ
This lil masterpiece was cooked up for perl v5.36.0 and dated 2022-10-15, living proudly as Agent::Driver(3pm). Go forth and log responsibly. π
π
π¦ where this page comes from
- ubuntu noble: liblog-agent-perl 1.005-2 Β· Artistic-2.0
- ubuntu resolute: liblog-agent-perl 1.005-2 Β· Artistic-2.0
- ubuntu stonking: liblog-agent-perl 1.005-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms