commit 23393a00219da04c2f0c1ab63b2084a84f011dbe from: Izzy Blacklock date: Sun Jul 02 18:22:52 2023 UTC Added debug() messages to libraries and tested Seems to work well using exported constants. commit - e3ad35bb3d83a37edc6a4aa29bcdb9287d42960f commit + 23393a00219da04c2f0c1ab63b2084a84f011dbe blob - 874bf924486cf2feebdfc2daa6a31bd0acbaba23 blob + 754a6137c0cf1d7f66a5fda6f10e009c403ba693 --- lib/IRCNOW/Database.pm +++ lib/IRCNOW/Database.pm @@ -3,8 +3,8 @@ package IRCNOW::Database; # Database modules use DBI; use DBD::SQLite; +use IRCNOW::IO qw(:DEBUG); - sub new { my ($class, @arguments) = @_; my $self = { @arguments }; @@ -101,6 +101,7 @@ sub dbInsertRecord { $sth->execute(@$_) or die $dbh->errstr; } } else { + debug(INFO,"INSERTING:". $stmt,$data); $dbh->do($stmt, undef, $data); } } blob - 805b7a46d0e4215407320f91f28eb2a123d0b0a4 blob + 0257da8cb85ccd468a9e1d1b94742073d9d3fe57 --- lib/IRCNOW/IO.pm +++ lib/IRCNOW/IO.pm @@ -9,10 +9,10 @@ our @EXPORT_OK = qw( # this enables loading lists of exports by tag like so: # use IRCNOW::IO qw(:DEBUG :FILEIO); our %EXPORT_TAGS = ( - DEBUG=>[qw(debug NONE INFO ERRORS WARNINGS ALL $dbLevel)], - FILEIO=>[qw(readarry readstr writefile appendfile)], + DEBUG=>[qw(debug NONE INFO ERRORS WARNINGS ALL $verbosity)], + FILEIO=>[qw(readarray readstr writefile appendfile)], ); -Exporter::export_ok_tags('debug'); +Exporter::export_ok_tags('debug', '$verbosity'); use File::Copy qw(copy); use File::Basename; @@ -21,7 +21,7 @@ use File::Basename; # Debug output # ####################################################################################### # Verbosity: 0 (no errors), 1 (errors), 2 (warnings), 3 (diagnostics) -# Using Constant Functions for inlining +# use constant { NONE => 0, ERRORS => 1, @@ -30,16 +30,18 @@ use constant { ALL => 4, }; +# Using Constant Functions for inlining +# alternative to use constant {}, #sub NONE () {0}; #sub ERROR () {1}; #sub WARNINGS () {2}; #sub INFO () {3}; #sub ALL () {4}; -our $dbLevel=ERRORS; + +our $verbosity=ERRORS; sub debug { my ($level, $msg) = @_; - print "[$dbLevel]>=[$level]\n"; - if ($dbLevel >= $level) { print "$msg\n"; } + if ($verbosity >= $level) { print "$msg\n"; } } ####################################################################################### blob - cb7c009d69ff505170d81ccb6a9cbeb1f46ef62f blob + 4a6a14d66ebd1fe55568b337689f1372c1a0a806 --- lib/IRCNOW/ParseLog/Znc.pm +++ lib/IRCNOW/ParseLog/Znc.pm @@ -5,6 +5,8 @@ use warnings; use lib qw(./lib); use IRCNOW::Database; +use IRCNOW::IO qw(:DEBUG); + use base qq{IRCNOW::ParseLog}; # Date string to epock used in init_ip_xref @@ -16,7 +18,7 @@ sub new { # Let base class setup and bless our object my $self = $class->SUPER::new( 'zncLog', @_ ); $self->set_dbCreate(qq{ - CREATE TABLE $self->{table} ( + CREATE TABLE $self->{TABLE} ( id INTEGER PRIMARY KEY, epoch integer, timestring VARCHAR(50), @@ -50,7 +52,7 @@ sub parseLog { my $type = 'Connected'; my $epoch = str2time($timeString); #Skip anything older then lastepoch - print "$skip, $epoch, $name, $ip\n"; + debug(ALL, "$skip, $epoch, $name, $ip\n"); if ( ($skip and $epoch == $lastEpoch) and ($name eq $lastName) and ($ip eq $lastIP) ) { blob - 3ca22d69e1b14ef6b79382b1a8375e9d2705774f blob + 5845d73610bef4f59ad64b8af2cfa4d9bea8407d --- parseznc.pl +++ parseznc.pl @@ -8,8 +8,7 @@ use lib qw(./lib); use IRCNOW::Database; use IRCNOW::ParseLog::Znc; use IRCNOW::IO qw(:DEBUG); -$dbLevel=ALL; -#our $dbLevel=INFO; +$verbosity=INFO; my $dbase='/var/www/botnow/botnow.db'; debug(INFO, "Loading Database $dbase"); my $botnowDB = IRCNOW::Database->new(dbpath=>$dbase); @@ -23,9 +22,9 @@ use Data::Dumper; my $lastRecord=$znclog->dbLastRecord() || []; my $data = $znclog->parseLog($lastRecord->[1],$lastRecord->[3],$lastRecord->[4]); -debug (ERRORS, Dumper($data)); +#debug (WARNINGS, Dumper($data)); -$znclog->dbInsertRecord($data); +#$znclog->dbInsertRecord($data); #print Dumper($znclog->parseLog($lastRecord->[1],$lastRecord->[3],$lastRecord->[4])); #$znclog->createTable();