NAME
Log::Agent::Logger - a logging interface
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 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
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 Log::Agent::Logger
extension will extend the set of available channels.
INTERFACE
Creation Routine
The creation routine is called make
and takes the following switches:
-channel
-
This defines the
Log::Agent::Channel
to be used for logging. Leaving this undefined will create a logger object that will never output anything. -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".
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 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.
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.
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.
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.
warn($str)
-
Log at the "warning" level, which is an indication that something unusual occurred.
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.
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. Furhter logging to the logger is permitted, but will be simply discarded without notice.
Attribute Access
The following access routines are defined:
channel
-
The defined logging channel. Cannot be changed.
max_prio
andmax_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
andmin_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_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 in Log::Agent::Priorities.
AUTHOR
Raphael Manfredi <Raphael_Manfredi@pobox.com>
SEE ALSO
Log::Agent::Channel(3).