From 8775053eb06a2c2bf8fd6995e1f42ea82e3c88b3 Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Fri, 15 Jan 2016 13:46:33 +0100 Subject: [PATCH] Fix wrong size/offset of log files with unicode characters that was breaking incremental mode. Thanks a lot to CZAirwolf for the report and the help to find the problem. --- pgbadger | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pgbadger b/pgbadger index a26da2a..0c9f751 100755 --- a/pgbadger +++ b/pgbadger @@ -2284,6 +2284,10 @@ sub process_file $line =~ s/\r//; + # Set current size and offset + $cursize += bytes($line); + $current_offset += bytes($line); + # Start to exclude from parsing any desired lines if ($has_exclusion >= 0) { @@ -2293,9 +2297,6 @@ sub process_file next if ($ef); } - $cursize += length($line); - $current_offset += length($line); - chomp($line); $nlines++; next if (!$line); @@ -2880,6 +2881,12 @@ sub check_file_changed return (1, "reach the end of check_file_changed() with start date: $saved_date and file size: $totalsize") ; } +# Return real size of ascii and unicode string. +sub bytes($) +{ + use bytes; + return length shift; +} # Method used to check if we have already reached the last parsing position in incremental mode # This position should have been saved in the incremental file and read in the $last_parsed at -- 2.40.0