Log::Agent::Logger(3pm) | User Contributed Perl Documentation | Log::Agent::Logger(3pm) |
Log::Agent::Logger - a logging interface
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: $!");
The "Log::Agent::Logger" class defines a generic interface for application logging. It must not be confused with the interface provided by Log::Agent, which is meant to be used by re-usable modules that do not wish to commit on a particular logging method, so that they remain true building blocks.
By contrast, "Log::Agent::Logger" explicitly requests an object to be used, and that object must commit upon the logging channel to be used, at creation time.
Optionally, minimum and maximum priority levels may be defined (and changed dynamically) to limit the messages to effectively log, depending on the advertised priority. The standard syslog(3) priorities are used.
The following channels are available:
Those channels are documented in Log::Agent::Channel.
Future "Log::Agent::Logger" extension will extend the set of available channels.
The creation routine is called "make" and takes the following switches:
I usually say something like:
-caller => [ -display => '($sub/$line)', -postfix => 1 ]
which I find informative enough. On occasion, I found myself using more complex sequences. See Log::Agent::Tag::Caller.
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.
At runtime, well after the creation of the logging object, 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.
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 be 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 is taken as a printf() format, and the remaining arguments are used to fill the various "%" placeholders in the format. The special "%m" placeholder does not make use of any extra argument and is replaced by a stringification of the error message contained in $!, aka "errno".
There is a logging routine defined for each syslog(3) priority, along with aliases for some of them. Here is an exhaustive table, sorted by decreasing priority.
Syslog Alias -------- --------- emerg emergency alert crit critical err error warning 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.
The following access routines are defined:
Please see Log::Agent::Tag::Caller to get the allowed parameters for list.
Please see Log::Agent::Tag::Priority to get the allowed parameters for list.
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.
Raphael Manfredi (Raphael_Manfredi@pobox.com) Mark Rogaski (mrogaski@cpan.org)
Log::Agent::Channel(3).
2021-09-27 | perl v5.32.1 |