]> granicus.if.org Git - pgbadger/commitdiff
Fix unwanted seek on old parsing position when log entry is stdin. Thanks to Olivier...
authorDarold Gilles <gilles@darold.net>
Wed, 1 Jul 2015 17:23:39 +0000 (19:23 +0200)
committerDarold Gilles <gilles@darold.net>
Wed, 1 Jul 2015 17:23:39 +0000 (19:23 +0200)
pgbadger

index e0cab5629c9432d99b330bd8ddbf0a69faa0e53e..c156f49c3734ee2847a2cf8b48d44d2273ceb7f9 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -1191,9 +1191,12 @@ if (!$remote_host) {
                my @tmpfilelist = ();
                # Removed files that have already been parsed during previous runs
                foreach my $f (@given_log_files) {
-                       if (!&check_file_changed($f, $saved_last_line{datetime})) {
+                       if ($f eq '-') {
+                               &logmsg('DEBUG', "waiting for log entries from stdin.");
+                               $saved_last_line{current_pos} = 0;
+                               push(@tmpfilelist, $f);
+                       } elsif (!&check_file_changed($f, $saved_last_line{datetime})) {
                                &logmsg('DEBUG', "this file has already been parsed: $f");
-                               next;
                        } else {
                                push(@tmpfilelist, $f);
                        }
@@ -2193,7 +2196,7 @@ sub process_file
                if ($#exclude_line >= 0) {
                        $has_exclusion = 1;
                }
-               &logmsg('DEBUG', "Start parsing at offset $start_offset of file $logfile to $stop_offset");
+               &logmsg('DEBUG', "Start parsing at offset $start_offset of file $logfile to " . ($stop_offset || $totalsize));
                if ($start_offset) {
                        # Move to the starting offset position in file
                        $lfile->seek($start_offset, 0);
@@ -12351,7 +12354,7 @@ sub get_log_file
        # get file size
        my $totalsize = 0;
        if (!$remote_host) {
-               $totalsize = (stat("$logf"))[7] || 0;
+               $totalsize = (stat("$logf"))[7] || 0 if ($logf ne '-');
        } elsif ($logf !~ /\.(gz|bz2|zip|xz)$/i) {
                &logmsg('DEBUG', "Looking for file size using command: $ssh_command \"ls -l $logf\" | awk '{print \$5}'");
                $totalsize = `$ssh_command "ls -l $logf" | awk '{print \$5}'`;
@@ -12374,7 +12377,7 @@ sub get_log_file
                        # Open a pipe to zcat program for compressed log
                        open($lfile,"$ssh_command \"cat $logf\" |") || die "FATAL: cannot read from pipe to $ssh_command \"cat $logf\". $!\n";
                }
-               $totalsize = 0 if ($lfile eq '-');
+               $totalsize = 0 if ($logf eq '-');
                $iscompressed = 0;
        } else {
                my $uncompress = $zcat;