NAME
CAF::Log - Simple class for handling log files
SYNOPSIS
use CAF::Log;
my $log = CAF::Log->new('/foo/bar', 'at');
$log->print("this goes to the log file\n");
$log->close();
DESCRIPTION
The CAF::Log class allows to instantiate objects for writing log files. A log file line can be prefixed by a time stamp.
Public methods
-
close(): booleancloses the log file, returns SUCCESS on success, undef otherwise (if no FH attribute exists).
-
print($msg): booleanPrints
$msginto the log file.If
PROCIDattribute is defined (value is irrelevant), the proces id in square brackets ([PID]) and additional space are prepended.If
TSTAMPattribute is defined (value is irrelevant), aYYYY/MM/DD-HH:mm:sstimestamp and additional space are prepended.No newline is added to the message.
Returns the return value of invocation of FH print method.
Private methods
-
_initialize($filename, $options)$optionsis a string with magic letters- a: append to a logfile
- w: truncate a logfile
- t: generate a timestamp on every print
- p: add PID
Only one of
woracan and has to be set. (There is no default.)If the
woption is used and there was a previous log file, it is renamed with the extension '.prev'.Examples: CAF::Log->new('/foo/bar', 'at'): append, enable timestamp CAF::Log->new('/foo/bar', 'w') : truncate logfile, no timestamp
If the filename ends with
.log, theSYSLOGattribute is set to basename of the file without suffix (relevant for CAF::Reporter::syslog). -
DESTROY
Called during garbage collection. Invokes close().