ABSTRACT

DESCRIPTION

This module is a vastly simplified logging system that can do nice stuff. Think of this module as a dispatcher for various logs.

This module *DOES NOT* do anything significant with logs, it simply routes them to the appropriate place ( Events )

You register a log that you are interested in, by telling SimpleLog the target session and target event. Once that is done, any log messages your program generates ( sent to SimpleLog of course ) will be massaged, then sent to the target session / target event for processing.

This enables an interesting logging system that can be changed during runtime and allow pluggable interpretation of messages.

One nifty idea you can do with this is:

Your program generally creates logs with the name of 'DEBUG'. You DCC Chat your IRC bot, then tell it to show all debug messages to you. All the irc bot have to do is register itself for all 'DEBUG' messages, and once you disconnect from the bot, it can unregister itself.

NOTE: There is no pre-determined log levels ( Like Log4j's DEBUG / INFO / FATAL / etc ) Arbitrary names can be used, to great effect. Logs with the names 'CONNECT', 'DB_QUERY', etc can be created.

This will set the alias SimpleLog uses in the POE Kernel. This will default TO "SimpleLog"

PRECISION

If this value is defined, SimpleLog will use Time::HiRes to get the timestamps.

Events

SimpleLog is so simple, there are only 5 events available.

REGISTER

This event accepts 3 arguments:
LOGNAME -> The name of the log to register for
SESSION -> The session where the log will go ( Also accepts Session ID's )
EVENT -> The event that will be called
The act of registering for a log can fail if one of the above values are undefined.
If the LOGNAME eq 'ALL', then that registration will get *ALL* the logs SimpleLog processes
There is no such thing as an "non-existant" log, registration just makes sure that you will get this log *WHEN* it comes.
Events that receive the logs will get these:
ARG0 -> CALLER_FILE
ARG1 -> CALLER_LINE
ARG2 -> Time::HiRes [ gettimeofday ] or time()
ARG3 -> LOGNAME
ARG4 -> Message
Here's an example:
$_[KERNEL]->post( 'SimpleLog', 'REGISTER',
LOGNAME => 'CONNECTION',
SESSION => $_[SESSION],
EVENT => 'GotLOG',
);
This is the subroutine that will get the GotLOG event
sub gotlog {
# Get the arguments
my( $file, $line, $time, $name, $message ) = @_[ ARG0 .. ARG4 ];
# Assumes PRECISION is undef ( regular time() )
print STDERR "$time ${name}-> $file : $line = $message\n";
# PRECISION = true ( Time::HiRes )
print STDERR "$time->[0].$time->[1] ${name}-> $file : $line = $message\n";
}

UNREGISTER

This event accepts 3 arguments:
LOGNAME -> The name of the log to unregister for
SESSION -> The session where the log will go ( Also accepts Session ID's )
EVENT -> The event that will be called
Unregistering for a log will fail if the exact 3 arguments were not found in our registry.
The act of unregistering will mean the session/event no longer receives any log messages.
NOTE: There might be some logs still traversing POE's queue...
Here's an example:
$_[KERNEL]->post( 'SimpleLog', 'UNREGISTER',
LOGNAME => 'CONNECTION',
SESSION => $_[SESSION]->ID,
EVENT => 'GotLOG',
);

UNREGISTERSESSION

This event accepts 1 argument:
ARG0 -> The session ( Also accepts Session ID's )
This is useful for removing all the registrations for a specific session.
Here's an example:
$_[KERNEL]->post( 'SimpleLog', 'UNREGISTERSESSION', $_[SESSION] );

LOG

This event accepts 2 arguments:
ARG0 -> Logname
ARG1 -> Message
This is where SimpleLog does it's work, sending the log to the proper events.
The Logname can be anything, if there is no events registered for it, the message will simply be discarded.
Here's an example:
$_[KERNEL]->post( 'SimpleLog', 'LOG', 'CONNECTION', 'A Client just connected!' );

SHUTDOWN

This is the generic SHUTDOWN routine, it will stop all logging.
Here's an example:
$_[KERNEL]->post( 'SimpleLog', 'SHUTDOWN' );