Log::A...Logger(3pm)
β¨ Log::A...Logger β¨
okay bestie, so this is the Log::Agent::Logger page from the User Contributed Perl Documentation, and it's literally your whole guide to a logging interface. it's giving "i want to log things and i want to be in charge of how". buckle up. π
πΈ NAME πΈ
Log::Agent::Logger β a logging interface. that's it, that's the name. iconic.
π SYNOPSIS π
require Log::Agent::Logger;
my $log = Log::Agent::Logger->make(
-channel => $chan,
-max_prio => 'info',
-min_prio => 'emerg',
);
$log->error("can't open file %s: $!", $file);
$log->warning("can't open file: $!");
see how easy? you make a logger, you tell it where to log and how loud, and then you just... log. periodt. π¦
π«Ά DESCRIPTION π«Ά
so the Log::Agent::Logger class defines a generic interface for application logging. do NOT confuse it with the interface that Log::Agent itself gives you β that one is meant for re-usable modules that don't wanna commit to any particular logging method, so they stay true building blocks. respectful. we love a flexible module.
by contrast, Log::Agent::Logger is the opposite vibe: it explicitly asks for an object to be used, and that object has to commit to the logging channel it's gonna use, at creation time. no take-backs at the altar, bestie.
optionally, minimum and maximum priority levels can be defined (and changed dynamically, like, whenever) to limit which messages actually get logged, depending on the advertised priority. and the priorities used are the standard syslog(3) ones. no cap. β
π CHANNEL LIST π
these are the channels you can pick from:
Standard Log::Agent Channels
those channels are documented over in Log::Agent::Channel. go look, i'll wait. π
Other Channels
future Log::Agent::Logger extension will extend the set of available channels. so like, more is coming. stay tuned, main character energy. β¨
π INTERFACE π
Creation Routine
the creation routine is called make and it takes these switches:
-caller=> [ parameters ] β asks that caller info (relative to the->log()call) be part of the log message. the parameters you give get handed off to the creation routine ofLog::Agent::Tag::Caller, and they're documented over there. i usually say something like:
-caller => [ -display => '($sub/$line)', -postfix => 1 ]
which i find informative enough. on occasion, i've found myself using more complex sequences. see Log::Agent::Tag::Caller. π§
-channelβ this defines theLog::Agent::Channelto be used for logging. please refer toLog::Agent::Channelfor details, and in particular to get a list of pre-defined logging channels.-min_prioβ defines the minimum priority to be logged (included). defaults to"emerg".-max_prioβ defines the maximum priority to be logged (included). defaults to"debug".-priority=> [ parameters ] β asks that message priority info be part of the log message. the given parameters get handed off to the creation routine ofLog::Agent::Tag::Priorityand are documented there. i usually say something like:
-priority => [ -display => '[$priority]' ]
which will display the whole priority name at the beginning of the messages, e.g. "[warning]" for a warn() or "[error]" for error(). see Log::Agent::Tag::Priority and Log::Agent::Priorities. π₯
-tags=> [ list ofLog::Agent::Tagobjects ] β specifies user-defined tags to be added to each message. the objects you give here must inherit fromLog::Agent::Tagand conform to its interface. seeLog::Agent::Tagfor details.
at runtime, well after the logging object was created, it may be desirable to add (or remove) a user tag. use the tags attribute to retrieve the tag list object and interact with it, as explained in Log::Agent::Tag_List. π
Logging Interface
each routine is documented to take a single string, but you may also supply a code reference as the first argument, followed by extra arguments. that routine will get called, along with the extra arguments, to generate the message to be logged. if that sounds crazy, think about the CPU time we save by NOT calling the routine. if nothing is returned by the routine, nothing is logged. π
if more than one argument is given, and the first argument is not a code reference, then it's taken as a printf() format, and the remaining arguments fill the various % placeholders in the format. the special %m placeholder does not use any extra argument and gets replaced by a stringification of the error message contained in $!, aka "errno". so convenient.
there's a logging routine defined for each syslog(3) priority, along with aliases for some of them. here's the exhaustive table, sorted by decreasing priority:
emergβ alias:emergencyalertcritβ alias:criticalerrβ alias:errorwarningβ alias:warnnoticeinfodebug
we shall document only one routine for a given level: for instance, we document warn but you could also use the standard warning to achieve exactly the same funciton. (yes, that typo is canon, i'm keeping it, it's part of the lore now. π)
emergency($str)β log at theemerglevel, usually just before panicing. something terribly bad has been detected, and the program might crash soon after logging this. so like, this is the "we're so cooked" message. πalert($str)β log at thealertlevel, to signal a problem requiring immediate attention. usually, some functionality will be missing until the condition is fixed. fix it bestie.critical($str)β log at thecritlevel, to signal a severe error that prevents fulfilling some activity.error($str)β log at theerrlevel, to signal a regular error. we've all been there.warn($str)β log at thewarninglevel, which is an indication that something unusual occurred. not an emergency, just... weird.notice($str)β log at thenoticelevel, indicating something that is fully handled by the applicaiton, but which is not the norm. a significant condition, as they say. (and yes,applicaitonis also canon, keeping it π )info($str)β log at theinfolevel, for their amusement.debug($str)β log at thedebuglevel, to further confuse them. π
Closing Channel
closeβ this routine closes the channel. further logging to the logger is permitted, but will be simply discarded without notice. so it just... goes into the void. no thoughts, head empty, message gone. π
Attribute Access
the following access routines are defined:
channelβ the defined logging channel. cannot be changed. locked in, no editing.max_prioandmax_prio_strβ returns the maximum priority recorded, either as a numeric value or as a string. for the correspondance between the two, seeLog::Agent::Priorities.min_prioandmin_prio_strβ returns the minimum priority recorded, either as a numeric value or as a string. for the correspondance between the two, seeLog::Agent::Priorities.set_caller_infolist β dynamically change the caller information formatting in the logs. the list given supersedes the initial settings done via the-callerargument, if any, and is passed to the creation routine of theLog::Agent::Tag::Callerclass. note that a plain list must be given, not a list ref. an empty list removes caller information from subsequent logs. please seeLog::Agent::Tag::Callerto get the allowed parameters for list.set_max_prio($prio)andset_min_prio($prio)β used to modify the maximum/minimum priorities. you can use either the string value or the numerical equivalent, as documented inLog::Agent::Priorities.set_priority_infolist β dynamically change the priority information formatting in the logs. the list given supersedes the initial settings done via the-priorityargument, if any, and is passed to the creation routine of theLog::Agent::Tag::Priorityclass. note that a plain list must be given, not a list ref. an empty list removes priority information from subsequent logs. please seeLog::Agent::Tag::Priorityto get the allowed parameters for list.tagsβ returns aLog::Agent::Tag_Listobject, which holds all user-defined tags that are to be added to each log message. the initial list of tags is normally supplied by the application at creation time, via the-tagsargument. seeLog::Agent::Tag_Listfor the operations that can be performed on that object. π
β AUTHORS β
Raphael Manfredi (Raphael_Manfredi@pobox.com) and Mark Rogaski (mrogaski@cpan.org). legends, honestly. π
π SEE ALSO π
and that's the whole page, bestie!! this was perl v5.32.1, dated 2021-09-27 β yeah she's a little vintage but she still slays. go forth and log responsibly. πβ¨π¦
π¦ where this page comes from
- debian bookworm: liblog-agent-logger-perl 0.201-1 Β· Artistic-1.0-Perl
- debian trixie: liblog-agent-logger-perl 0.201-1 Β· Artistic-1.0-Perl
- ubuntu jammy: liblog-agent-logger-perl 0.201-1 Β· Artistic-1.0-Perl
- ubuntu noble: liblog-agent-logger-perl 0.201-1 Β· Artistic-1.0-Perl
- ubuntu resolute: liblog-agent-logger-perl 0.201-1 Β· Artistic-1.0-Perl
- ubuntu stonking: liblog-agent-logger-perl 0.201-1 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms