new()

Constructor for logger class.

Takes one argument: template (using %*, strftime variables).

This argument can also be reference to File Handle to force log output to given stream. This can be used for example like:

my $logger = OmniPITR::Log->new( \*STDOUT );

_log()

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)'.

For client-code open methods check log(), error() and fatal().

log()

Client code facing method, which calls internal _log() method, giving 'LOG' as loglevel, and passing rest of arguments without modifications.

Example:

$logger->log( 'i = %u', $i );

error()

Client code facing method, which calls internal _log() method, giving 'ERROR' as loglevel, and passing rest of arguments without modifications.

Example:

$logger->error( 'File creation failed: %s', $OS_ERROR );

fatal()

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.

Example:

$logger->fatal( 'Called from user with uid = %u, and not 0!', $user_uid );

time_start()

Starts timer.

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.

time_finish()

Finished calculation of time for given block of code.

Calling:

$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.

_get_log_line_prefix()

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

_get_log_fh()

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.