|
Log::AndError - Logging module for ISA inclusion in other modules or as a standalone module. |
service_name()debug_level()info_level()alwayslog_level()template()error()error_code()error_msg()logger()
Log::AndError - Logging module for ISA inclusion in other modules or as a standalone module.
use Log::AndError;
@ISA = qw(Log::AndError);
Remember to set values with the provided methods
or
use Log::AndError;
use Log::AndError::Constants qw(:all);
my $ref_logger = Log::AndError->new(
'LOG_LOGGER' => \&log_sub,
'LOG_SERVICE_NAME' => 'GENERIC', # Use this to seperate log entries from different modules in your app.
'LOG_DEBUG_LEVEL' => DEBUG1, # See Log::AndError::Constants for example
'LOG_INFO_LEVEL' => INFO, # See Log::AndError::Constants for example
'LOG_ALWAYSLOG_LEVEL' => ALWAYSLOG, # See Log::AndError::Constants for example
);
$self->logger(DEBUG3, 'my_sub('.join(',',@_).')');
# for instance logs the entry into a subroutine.
$self->logger(ALWAYSLOG, 'Something is wrong');
# logs an error when it is always wanted
After you do this:
$self->error($error_code, $error_msg);
Your Caller does this:
my($err,$msg) = $obj_ref->error();
to retrieve the errors.
This is a generic log and error class for Perl modules. There are two distinct pieces here. The error functions and the logging. The error functions are most convenient when inherited by your package although this is not needed. They are mostly here for convenience and to promote ``good'' behavior. The logging functions are the more complex piece and is the bulk of the code.
To use the logging function pass in a reference to an anonymous sub routine that directs the error output to where you want it to go. There are a few sample subs located under this class. The default outputs to STDERR via warn().
The DEBUG constants are always >=0 and the ALWAYSLOG and INFO type constants always need to be <= -2 (-1 == undef on most systems). See Log::AndError::Constants for an example.
Examples forthcoming at some point.
Hey, it beats overwriting %SIG{__WARN__} with an anonymous sub for error string grabbing.
service_name()Log::AndError::service_name()
$service_name = $obj_ref->service_name(); #From Caller's Perspective
or
$self->service_name('GENERIC');
debug_level()Log::AndError::debug_level()
$debug = $obj_ref->debug_level(); #From Caller's Perspective
or
$self->debug_level(1);
info_level()Log::AndError::info_level()
$info_level = $obj_ref->info_level(); #From Caller's Perspective
or
$self->info_level(INFO); # -2 from Log::AndError::Constants
alwayslog_level()Log::AndError::alwayslog_level()
$alwayslog_level = $obj_ref->alwayslog_level(); #From Caller's Perspective
or
$self->alwayslog_level(ALWAYSLOG); # -3 from Log::AndError::Constants
template()Log::AndError::template()
my $template = $obj_ref->template(); #From Caller's Perspective
or
my $template = $self->template("%s: LEVEL[%d]: %s");
sprintf() template for the logging method. It must have a %s(string), %d(decimal), %s(string) format to it. What you place in between is up to you. The default is in the POD above and can be retrieved at runtime from the return value.
error()Log::AndError::error()
my($err,$msg) = $obj_ref->error(); #From Caller's Perspective
or
$self->error($error_code, $error_msg);
error_code() and error_msg() functions. Remember that this is most useful when inherited by your module via ISA.
error_code()Log::AndError::error_code()
$err = $obj_ref->error_code(); #From Caller's Perspective
or
$self->error_code($code);
error_msg()Log::AndError::error_msg()
$msg = $obj_ref->error_msg(); #From Caller's Perspective
or
$self->error_msg($msg);
logger()Log::AndError::logger()
my($err, $msg) = $self->logger(DEBUG_CONSTANT, $msg);
Thomas Bolioli <Thomas_Bolioli@alumni.adelphi.edu>
Thanks to John Ballem of Brown University for the Constants module and the push to do this one.
Copyright (c) 2001 Thomas Bolioli. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Log::AndError - Logging module for ISA inclusion in other modules or as a standalone module. |