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: $!");

DESCRIPTION

The \*(C`Log::Agent::Logger\*(C' 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, \*(C`Log::Agent::Logger\*(C' explicitely 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.

CHANNEL LIST

The following channels are available:

Standard Log::Agent Channels

Those channels are documented in Log::Agent::Channel.

Other Channels

Future \*(C`Log::Agent::Logger\*(C' extension will extend the set of available channels.

INTERFACE

Creation Routine

The creation routine is called \*(C`make\*(C' and takes the following switches: Request that caller information (relative to the ->log() call) be part of the log message. The given parameters are handed off to the creation routine of \*(C`Log::Agent::Tag::Caller\*(C' and are documented there. 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. This defines the \*(C`Log::Agent::Channel\*(C' 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. Defines the minimum priority to be logged (included). Defaults to \*(L"emerg\*(R". Defines the maximum priority to be logged (included). Defaults to \*(L"debug\*(R". Request that message priority information be part of the log message. The given parameters are handed off to the creation routine of \*(C`Log::Agent::Tag::Priority\*(C' 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. \*(L"[warning]\*(R" for a warn() or \*(L"[error]\*(R" for error(). See Log::Agent::Tag::Priority and Log::Agent::Priorities. Specifies user-defined tags to be added to each message. The objects given here must inherit from \*(C`Log::Agent::Tag\*(C' and conform to its interface. See Log::Agent::Tag for details. At runtime, well after the creation of the logging object, it may be desirable to add (or remove) a user tag. Use the \*(C`tags\*(C' 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 be called, along with the extra arguments, to generate the message to be logged. If that sounds crazy, think about the \s-1CPU\s0 time we save by \s-1NOT\s0 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 \*(L"%\*(R" placeholders in the format. The special \*(L"%m\*(R" placeholder does not make use of any extra argument and is replaced by a stringification of the error message contained in $!, aka \*(C`errno\*(C'.

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 \*(C`warn\*(C' but you could also use the standard \*(C`warning\*(C' to achieve exactly the same funciton. Log at the \*(L"emerg\*(R" level, usually just before panicing. Something terribly bad has been detected, and the program might crash soon after logging this. Log at the \*(L"alert\*(R" level, to signal a problem requiring immediate attention. Usually, some functionality will be missing until the condition is fixed. Log at the \*(L"crit\*(R" level, to signal a severe error that prevents fulfilling some activity. Log at the \*(L"err\*(R" level, to signal a regular error. Log at the \*(L"warning\*(R" level, which is an indication that something unusual occurred. Log at the \*(L"notice\*(R" level, indicating something that is fully handled by the applicaiton, but which is not the norm. A significant condition, as they say. Log at the \*(L"info\*(R" level, for their amusement. Log at the \*(L"debug\*(R" level, to further confuse them.

Closing Channel

This routine closes the channel. Further logging to the logger is permitted, but will be simply discarded without notice.

Attribute Access

The following access routines are defined: The defined logging channel. Cannot be changed. Returns the maximum priority recorded, either as a numeric value or as a string. For the correspondance between the two, see Log::Agent::Priorities. Returns the minimum priority recorded, either as a numeric value or as a string. For the correspondance between the two, see Log::Agent::Priorities. Dynamically change the caller information formatting in the logs. The list given supersedes the initial settings done via the \*(C`-caller\*(C' argument, if any, and is passed to the creation routine of the \*(C`Log::Agent::Tag::Caller\*(C' 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. Used to modify the maximum/minimum priorities. You can use either the string value or the numerical equivalent, as documented in Log::Agent::Priorities. Dynamically change the priority information formatting in the logs. The list given supersedes the initial settings done via the \*(C`-priority\*(C' argument, if any, and is passed to the creation routine of the \*(C`Log::Agent::Tag::Priority\*(C' 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. Returns a \*(C`Log::Agent::Tag_List\*(C' 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 \*(C`-tags\*(C' argument. See Log::Agent::Tag_List for the operations that can be performed on that object.

AUTHOR

Raphael Manfredi <[email protected]>

RELATED TO Log::Agent::Logger…

Log::Agent::Channel\|(3).