I'll see what I can do about extracting what I think are the relevant bits :)
here is the gist of csLogs::Error.pm
package Error; use Exporter (); @ISA = qw(Exporter); @EXPORT = qw( csWarn csDie ); use lib 'f:/projects/site/bin/config/'; use strict; use utf8; use csLogsConfig; #================================================== # Replacements for User-called warn and die #-------------------------------------------------- # to be used instead of warn() in application code sub csWarn { takes error class/severity and diagnostics info as parameters . . . } #-------------------------------------------------- # to be used instead of die() in application code sub csDie { very similar to csWarn, except that it exit()'s on completion . . . } #================================================== # Private Functions . . . #================================================== #Overload SIGWARN and SIGDIE BEGIN { sub csWarnHandle { much like csWarn except with default parameters } sub csDieHandle { much like csDie except with default parameters } $SIG{__WARN__} = \&csWarnHandle; $SIG{__DIE__} = \&csDieHandle; } #---- 1;
here is pieces of csDB, which is a wrapper for the DBI
package csDB; use Exporter (); @ISA = qw(Exporter); @EXPORT = qw(QueryDB $dbh); use lib 'f:/projects/site/bin/config/'; use strict; use DBI; use csConfig; use csLogs::Error; our $dbh; #===================================================================== +===================================== # Database Connection BEGIN { $dbh = DBI->connect(csDBAuth()) or csDie( class=>csErrorClass('SERVER_DATABASE'),severity=>csErrorSca +le('CRITICAL'), message=>'Could not connect to database server', debug=>$DBI::errstr ); } END { $dbh->disconnect(); } #===================================================================== +===================================== sub QueryDB { $dbh->{RaiseError}=0; $dbh->{PrintError}=0; my $qstring = $_[0]; my $dbquery= $dbh->prepare("$qstring") or csDie( class=>csErrorClass('CODE_DATABASE'),severity=>csErrorScale +('SEVERE'), message=>'Database Query Preparation Error', debug=>$DBI::errstr ); $dbquery->execute or csDie( class=>csErrorClass('CODE_DATABASE'),severity=>csErrorScale +('SEVERE'), message=>'Database Query Execution Error', debug=>$DBI::errstr ); $dbh->{RaiseError}=1; $dbh->{PrintError}=1; return ($dbquery); } #===================================================================== +===================================== other handy functions . . .
and finally the script that i was testing upon discovering this issue, csErrorLog_Parser
use lib 'f:/projects/site/bin/config/'; use strict; use utf8; use csConfig; use csLogsConfig; use csLogs::Error; use csLogs::Event; use csDB; if (-f &csErrorLog) # file exists and needs to be processed { my $tmp_logfile = csPath('logs').'/errors'.time().'.log'; my $LOG = undef; #--------------------------------- # renaming the file assures that the processing # this script does doesn't interfere with normal logging. rename(&csErrorLog,$tmp_logfile) or csDie( class=>csErrorClass('CO +DE_FILE_IO'),severity=>csErrorScale('MODERATE'), message=>'Error Log Parser + could not rename log to a temporary file.', debug=>"original filename: + '".&csErrorLog."'\nnew filename: '$tmp_logfile'" ); open($LOG,$tmp_logfile) or csDie( class=>csErrorClass('CODE_FILE_I +O'),severity=>csErrorScale('MODERATE'), message=>'Error Log Parser + could not open the renamed log file.', debug=>"filename: '$tmp_lo +gfile'" ); #--------------------------------- # process the entries my $entries = process_errorlog($LOG); Event::NoteEvent( class=>csEventClass('TOOL_ACTION'),importance=>c +sEventScale('LOW'), message=>'Error Log Parser successfully processed the e +rror log', info=>"$entries log entries processed from '".&csErrorL +og."'" ); #--------------------------------- # with processing completed dispose of the temp log file. close($LOG); unlink($tmp_logfile) or csDie( class=>csErrorClass('CODE_FILE_IO') +,severity=>csErrorScale('MODERATE'), message=>'Error Log Parser + could remove the renamed log file.', debug=>"filename: '$tmp_lo +gfile'" ); } else # file doesn't exist and no processing was necessary { Event::NoteEvent( class=>csEventClass('TOOL_ACTION'),importance=>c +sEventScale('LOW'), message=>"Error Log Parser ran but '".&csErrorLog."' wa +s not found", info=>"parser assumes no errors have been logged since +the parser was last run." ); } #exit #===================================================================== +=========================== sub process_errorlog { my $LOG = $_[0]; my $entries = 0; # track num of entries processed. my $state = 'none'; #state of the parser; my ( $time, $class, $severity, $message, $debug ) = (); #--------------------------------- # walk the file while( <$LOG> ) { ....fun with regex's and such.... } if( $time ) { ....temporary inelegance to flush out the last record.... } return $entries; }
In reply to Re: Re: Re: Re: exporter and multiple namespaces
by AidanLee
in thread exporter and multiple namespaces
by AidanLee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |