remove all output without DEBUG=1 for cron use master
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Jul 2023 07:54:20 +0000 (09:54 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Jul 2023 07:54:20 +0000 (09:54 +0200)
parse-node-logs.pl

index 7e0d4ad..5b973fd 100755 (executable)
@@ -10,20 +10,23 @@ use autodie;
 
 my $path = '/home/nodelogs/c405f97667784094bca5cfa52af0bcf1/';
 
+my $last_files = $ENV{LAST} || 3; # process last 3 logs by mtime
+
+my $debug = $ENV{DEBUG} || 0;
+
 # select _id,json->'received',time,to_timestamp((json->>'received')::int8/1000) - interval '1 hour' from nodelog ;
 
 my $dbh = DBI->connect("dbi:Pg:dbname=eg5120", "dpavlin", "", { RaiseError => 1 });
-warn "# truncate table nodelog";
+warn "# truncate table nodelog" if $debug;
 $dbh->do( qq{ truncate table nodelog } ); # FIXME
 my $sth = $dbh->prepare(qq{insert into nodelog (time,json) values (?,?)});
 
-my $last_files = $ENV{LAST} || 3; # process last 3 logs by mtime
 
 foreach my $filename (
                sort { -M $a <=> -M $b } (glob("$path/node-red-out*.log")),
        ) {
        last if $last_files-- == 0;
-       warn "# $filename";
+       warn "# $filename" if $debug;
        open(my $log, '<', $filename);
        my $in_json = 0;
        my $json;
@@ -50,7 +53,7 @@ foreach my $filename (
                        if ( $_ eq '}' ) {
                                $in_json = 0;
                                #warn "- in_json";
-                               warn ">>> $time [[[[ $json ]]]]";
+                               warn ">>> $time [[[[ $json ]]]]" if $debug;
                                write_file '/dev/shm/json', $json;
                                $sth->execute( $time, $json );
                                $json = '';