NAME
PAB3::Logger - Logging extension to PAB3
SYNOPSIS
use PAB3::Logger;
$logger = PAB3::Logger->new(
'file' => '/path/to/log/file'
);
$logger->debug( 'debugging message' );
$logger->info( 'informative message' );
$logger->warn( 'warning message' );
$logger->error( 'error message' );
DESCRIPTION
PAB3::Logger provides an interace for logging methods.
Depending on the the current LogLevel setting, only logging with the same log level or higher will be loaded. For example if the current LogLevel is set to warning, only messages with log level of the level warning or lower (error) will be logged.
METHODS
- new ( %arg )
-
Creates a new logger class.
Parameters
%arg
A combination of the following parameters:
level => a logging level file => a target file or handle to write log message to format => a logging format header => a header message (info) to be send on every session utils => a reference to a PAB3::Utils class
level
The logging level. Only messages with log level of the level defined or lower will be logged. Default level is 2.
0 - log nothing 1 - log error messages 2 - log warning messages 3 - log informative messages 4 - log debugging messages
file
A filename or a file handle to write to.
Example
# using STDERR PAB3::Logger->new( 'file' => \*STDERR, );
format
A log format string. Following parameters are defined
%t Current time in format mmm dd HH:MM:SS %p Process ID ($$) %r Runtime ID, a randomly generated id %e Elapsed time in seconds (i.e. 0.0025 = 2.5 ms) %c Client (REMOTE_ADDR or USER)
header
A string to be send on every session starting by new() or reset(). The header will send as level "info".
utils
A reference to a PAB3::Utils class to write log time returned by utils->localtime().
Return Values
Returns a new logger class.
Example
$logger = PAB3::Logger->new( 'file' => '/path/to/log/file', 'level' => 4, # log all 'format' => '[%t] [%p] [%r] [%c] [%e]', 'header' => '--- starting session ---', ); ... # end of script $logger->info( 'session finished' );
- send ( $msg )
- send ( $msg, $level )
-
Send a message with the specified level. If no level is defined, default level of 2 will be used.
- debug ( $msg )
-
Send a debugging message to the logger. Maps to send( $msg, 4 )
- info ( $msg )
-
Send an informative message to the logger. Maps to send( $msg, 3 )
- warn ( $msg )
-
Send a warning message to the logger. Maps to send( $msg, 2 )
- error ( $msg )
-
Send an error message to the logger. Maps to send( $msg, 1 )
- reset ()
-
Resets the elapsed time and sends a log header if provided.
AUTHORS
Christian Mueller <christian_at_hbr1.com>
COPYRIGHT
The PAB3::Logger module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.