The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

POE::Component::GCS::Server::Log - Generic server logging

VERSION

This document describes version 0.02, released February, 2005.

SYNOPSIS

use POE::Component::GCS::Server::Log;
spawn POE::Component::GCS::Server::Log ( LoggingLevel );

$Log = "POE::Component::GCS::Server::Log";

$Log->write( $command_string );

DESCRIPTION

This class is used to validate and dispatch commands within a generic network server daemon. To cleanly subclass, simply override the dispatch method. If the generic commands, described below, remain implemented in the Maintenance and Proc classes, there is no need to override the genericCommands method.

Note that this module is not event driven. The assumption is that an application's logging function should be synchronous. As such, this generic class is implemented to immediately write messages to the system's log file and flush the log buffer if necessary.

Constructor

spawn ( [ LoggingLevel ] )

This creates a new generic server log object. Note that the object created is implemented as a 'singleton', meaning that any subsequent calls to this method will return the original object created by the first call to this method.

The optional LoggingLevel parameter can be added to specify the amount of logging that will occur. By default, the initial LoggingLevel is set to a value of 3.

Methods

log ( LogLevel, LogText )
write ( LogLevel, LogText )

This method writes the LogText to the application's log file. If the LogLevel is greater than the initial LoggingLevel specified when spawning this service, the message is not written to the log file.

LogLevel

This LogLevel parameter is compared with the initial LoggingLevel to determine wheather the log message will be written or not.

LogText

This is a string of text written to the log file. Note that a date is prepended to the message. By default, the date string is simply the number returned by Perl's time() function.

error ( LogLevel, LogText )
warn ( LogLevel, LogText )

These methods are provided as a simple alternative to the builtin Perl warn function, in a manner compatible with the above 'log' and 'write' methods, and the arguments are indentical to those described above.

formatDate ( )

This method is provided to simplify subclassing this module. All this method needs to do is return a formatted date string. This short example implements a complete subclass that changes the default date (prepended to each log message) with a foratted string.

package My::Custom::Logger;
use strict;
use warnings;
our @ISA = qw( POE::Component::GCS::Server::Log );

use POE::Component::GCS::Server::Log;
use Date::Format;

$DateFormat = "%Y%m%d %H:%M:%S";      # 20050516 19:05:39

sub formatDate { time2str( $DateFormat, time() ) }
#_________________________
1; # Required by require()
setLogLevel ( [ LoggingLevel ] )
incrLogLevel ( IncreaseBy )
decrLogLevel ( DecreaseBy )

These methods can be used to set, increment or decrement the initial LoggingLevel set when an object of this class was first instantiated. By default the LoggingLeve is set to 3. Other than that, usage should be obvious.

getLogLevel ( )

This method returns the LoggingLevel currently in use.

DEPENDENCIES

None currently.

SEE ALSO

For discussion of the generic server, see POE::Component::GCS::Server. For discussion of server configuration, see POE::Component::GCS::Server::Cfg.

AUTHOR

Chris Cobb, <no spam [at] ccobb [dot] net>

COPYRIGHT

Copyright (c) 2005-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.