Commit Diff


commit - 618ba1715bb12777f4afd3312d02c3c4501b43f2
commit + e3ad35bb3d83a37edc6a4aa29bcdb9287d42960f
blob - bb95f971cfac3a52b38c9e9a460a6a42cfe933be
blob + 805b7a46d0e4215407320f91f28eb2a123d0b0a4
--- lib/IRCNOW/IO.pm
+++ lib/IRCNOW/IO.pm
@@ -1,9 +1,50 @@
-package IRCNOW::IO
+package IRCNOW::IO;
+use Exporter 'import';
 
+our @EXPORT_OK = qw(
+	readarray readstr writefile appendfile
+	debug NONE INFO ERRORS WARNINGS ALL $dbLevel	
+);
+# create debug tag so you can import the debug sub and messages
+# 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)],
+);
+Exporter::export_ok_tags('debug');
+
 use File::Copy qw(copy);
 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,
+	WARNINGS => 2,
+	INFO => 3,
+	ALL => 4,
+};
 
+#sub NONE () {0};
+#sub ERROR () {1};
+#sub WARNINGS () {2};
+#sub INFO () {3};
+#sub ALL () {4};
+our $dbLevel=ERRORS;
+sub debug {
+	my ($level, $msg) = @_;
+	print "[$dbLevel]>=[$level]\n";
+	if ($dbLevel >= $level) { print "$msg\n"; }
+}
+
+#######################################################################################
+#                                       Basic file IO                                 #
+#######################################################################################
 # Read from filename and return array of lines without trailing newlines
 sub readarray {
 	my ($filename) = @_;
@@ -40,3 +81,5 @@ sub appendfile {
 	close $fh;
 }
 
+1;
+
blob - c67b474a69aed2c49bb101bb3d1e67162277e74d
blob + 3ca22d69e1b14ef6b79382b1a8375e9d2705774f
--- parseznc.pl
+++ parseznc.pl
@@ -7,9 +7,13 @@ use warnings;
 use lib qw(./lib);
 use IRCNOW::Database;
 use IRCNOW::ParseLog::Znc;
+use IRCNOW::IO qw(:DEBUG);
+$dbLevel=ALL;
+#our $dbLevel=INFO;
+my $dbase='/var/www/botnow/botnow.db';
+debug(INFO, "Loading Database $dbase");
+my $botnowDB = IRCNOW::Database->new(dbpath=>$dbase);
 
-my $botnowDB = IRCNOW::Database->new(dbpath=>'/var/www/botnow/botnow.db');
-
 my $znclog = IRCNOW::ParseLog::Znc->new(
 	database=>$botnowDB,
 	zncLog=>'/home/znc/home/znc/.znc/moddata/adminlog/znc.log',
@@ -19,7 +23,7 @@ use Data::Dumper;
 
 my $lastRecord=$znclog->dbLastRecord() || [];
 my $data = $znclog->parseLog($lastRecord->[1],$lastRecord->[3],$lastRecord->[4]);
-print Dumper($data);
+debug (ERRORS, Dumper($data));
 
 $znclog->dbInsertRecord($data);
 #print Dumper($znclog->parseLog($lastRecord->[1],$lastRecord->[3],$lastRecord->[4]));