Guide Home
POD Home

Sloop::Logger

DESCRIPTION

Sloop::Logger is a simple class for logging to open filehandles. It is used by many of the other Sloop classes. If you wish to subclass it (e.g., because you prefer the log be opened and closed for each message), the only method you need to override is out().

SYNOPSIS

 use Sloop::Logger;
 my $log = Sloop::Logger->new (
        logs => (optional) Reference to array of 3 file handle refs.
 );

There should be three entries in the 'logs' array; these are indexed corresponding to the constants exported by this module:

 0 = LOG_ERR
 1 = LOG_DEBUG
 2 = LOG_REQUEST

The entries themselves should be file handle references. If not specified, defaults to [ \*STDERR, \*STDERR, \*STDOUT ]

The constructor then turns off line buffering, a.k.a. turns on autoflush, for all three handles.

Logger is inflexible in terms of formatting the output, but can be easily subclassed to override the out() method below.

ATTRIBUTES

The logs array is accessible and can be modified at any point.

METHODS

$log->out($fh_index, $message)

$fh_index is one of the the LOG_ values from Sloop::Constant (see constructor synopsis above).

$message is the text to print to the log.

This appends a timestamp as described in the timestamp() method below.

If you subclass Logger to override this method, it will handle all calls to print messages via the logger object, such as the err_log() method of Sloop::Base inherited by Sloop::Client and Sloop::Server.

$log->timestamp()

Returns a timestamp corresponding to the current local time in the form:

 DD [Month] HH:MM:SS

That's the day, the month in three letters, (e.g. "Jan"), and the time. A space is appended at the end.