Constructor for logger class.
Takes one argument: template (using %*, strftime variables).
Internal function, shouldn't be called from client code.
Gets loglevel (assumed to be string), format, and list of values to fill-in in the format, using standard sprintf semantics.
Each line (even in multiline log messages) is prefixed with metainformation (timestamp, pid, program name).
In case reference is passed as one of args - it is dumped using Data::Dumper.
Thanks to this this:
$object->_log('loglevel', '%s', $object);
Will print dump of $object and not stuff like 'HASH(0xdeadbeef)'.
Client code facing method, which calls internal _log() method, giving 'LOG' as loglevel, and passing rest of arguments without modifications.
$logger->log( 'i = %u', $i );
Client code facing method, which calls internal _log() method, giving 'ERROR' as loglevel, and passing rest of arguments without modifications.
$logger->error( 'File creation failed: %s', $OS_ERROR );
Client code facing method, which calls internal _log() method, giving 'FATAL' as loglevel, and passing rest of arguments without modifications.
Additionally, after logging the message, it exits main program, setting error status 1.
$logger->fatal( 'Called from user with uid = %u, and not 0!', $user_uid );
Should be used together with time_finish, for example like this:
$logger->time_start( 'zipping' ); $zip->run(); $logger->time_finish( 'zipping' );
Arguments to time_start and time_finish should be the same to allow matching of events.
Finished calculation of time for given block of code.
$logger->time_finish( 'Compressing with gzip' );
Will log line like this:
2010-04-09 00:08:35.148118 +0200 : 19713 : omnipitr-archive : LOG : Timer [Compressing with gzip] took: 0.351s
Assuming related time_start() was called 0.351s earlier.
Internal method generating line prefix, which is prepended to every logged line of text.
Prefix contains ( " : " separated ):
Timestamp, with microsecond precision
Process ID (PID) of logging program
Name of program that logged the message
Internal method handling logic to close and open logfiles when necessary, based of given logfile template, current time, and when previous logline was logged.
At any given moment only 1 filehandle will be opened, and it will be closed, and reopened, when time changes in such way that it would require another filename.