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 of Log::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 the Log::Agent::Channel to be used for logging. please refer to Log::Agent::Channel for 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 of Log::Agent::Tag::Priority and 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 of Log::Agent::Tag objects ] β€” specifies user-defined tags to be added to each message. the objects you give here must inherit from Log::Agent::Tag and conform to its interface. see Log::Agent::Tag for 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: emergency
  • alert
  • crit β€” alias: critical
  • err β€” alias: error
  • warning β€” alias: warn
  • notice
  • info
  • debug

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 the emerg level, 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 the alert level, 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 the crit level, to signal a severe error that prevents fulfilling some activity.
  • error($str) β€” log at the err level, to signal a regular error. we've all been there.
  • warn($str) β€” log at the warning level, which is an indication that something unusual occurred. not an emergency, just... weird.
  • notice($str) β€” log at the notice level, indicating something that is fully handled by the applicaiton, but which is not the norm. a significant condition, as they say. (and yes, applicaiton is also canon, keeping it πŸ’…)
  • info($str) β€” log at the info level, for their amusement.
  • debug($str) β€” log at the debug level, 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_prio and max_prio_str β€” returns the maximum priority recorded, either as a numeric value or as a string. for the correspondance between the two, see Log::Agent::Priorities.
  • min_prio and min_prio_str β€” returns the minimum priority recorded, either as a numeric value or as a string. for the correspondance between the two, see Log::Agent::Priorities.
  • set_caller_info list β€” dynamically change the caller information formatting in the logs. the list given supersedes the initial settings done via the -caller argument, if any, and is passed to the creation routine of the Log::Agent::Tag::Caller class. note that a plain list must be given, not a list ref. an empty list removes caller information from subsequent logs. please see Log::Agent::Tag::Caller to get the allowed parameters for list.
  • set_max_prio($prio) and set_min_prio($prio) β€” used to modify the maximum/minimum priorities. you can use either the string value or the numerical equivalent, as documented in Log::Agent::Priorities.
  • set_priority_info list β€” dynamically change the priority information formatting in the logs. the list given supersedes the initial settings done via the -priority argument, if any, and is passed to the creation routine of the Log::Agent::Tag::Priority class. note that a plain list must be given, not a list ref. an empty list removes priority information from subsequent logs. please see Log::Agent::Tag::Priority to get the allowed parameters for list.
  • tags β€” returns a Log::Agent::Tag_List object, 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 -tags argument. see Log::Agent::Tag_List for 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 πŸ”—

Log::Agent::Channel(3).


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. πŸ’–βœ¨πŸ¦‹