]> granicus.if.org Git - pgbadger/commitdiff
Fix incomplete lines in split_logfile to rewind to the begining of the line. Thanks...
authorDarold Gilles <gilles@darold.net>
Mon, 7 Apr 2014 17:39:02 +0000 (19:39 +0200)
committerDarold Gilles <gilles@darold.net>
Mon, 7 Apr 2014 17:39:02 +0000 (19:39 +0200)
pgbadger

index 624e9706b198d0b5ef0028373055dc8b362d0b91..476810fa769de05e618415edf28a2c86283c6f28 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -1584,6 +1584,7 @@ sub process_file
 
                        $cursize += length($line);
                        $current_offset += length($line);
+
                        chomp($line);
                        $line =~ s/\r//;
                        $nlines++;
@@ -9984,10 +9985,26 @@ sub split_logfile
                $chunks[0] = $saved_last_line{current_pos};
                $i = $saved_last_line{current_pos};
        }
+       my ($lfile, $null) = &get_log_file($logf); # Get file handle to the file
        while ($i < $queue_size) {
                push(@chunks, int(($totalsize/$queue_size) * $i));
+               my $pos = int(($totalsize/$queue_size) * $i);
+               my $safe_pos = $pos;
+               # Goto the position of that chunk and rewind to the begining of the line
+               # Do not rewind more than 1OK to prevent infinite loop.
+               my $line = '';
+               my @matches = ();
+               do {
+                       $lfile->seek($pos, 0);
+                       $line = <$lfile>;
+                       @matches = ($line =~ $compiled_prefix);
+                       $pos-- if (@matches < 0);
+               } while ((@matches < 0) && ($pos > ($safe_pos - 10000)));
+               # Get EOL position
+               push(@chunks, $pos);
                $i++;
        }
+       $lfile->close();
        push(@chunks, $totalsize);
 
        return @chunks;