]> granicus.if.org Git - pgbadger/commitdiff
Fix --exclude-line options and removing of obsolete directory when retention is enabl...
authorGilles Darold <gilles.darold@dalibo.com>
Mon, 2 Jan 2017 22:23:41 +0000 (23:23 +0100)
committerGilles Darold <gilles.darold@dalibo.com>
Mon, 2 Jan 2017 22:23:41 +0000 (23:23 +0100)
pgbadger

index ae4973688c2e760138b6faaa0a69899a2d5c38f0..c129dc295858d9c1f67a7340f6ee272d653a6db4 100644 (file)
--- a/pgbadger
+++ b/pgbadger
@@ -1264,9 +1264,16 @@ if ( $outdir && $retention && ($saved_last_line{datetime} || $pgb_saved_last_lin
                                                        push(@rmdays, $d);
                                                }
                                        } else {
-                                               # Remove obsolte days when we are in binary mode
+                                               # Remove obsolete days when we are in binary mode
                                                # with noreport - there's no week-N directory
-                                               if ("$y$weekNumber" lt $limit) {
+                                               my $diff_day = $retention * 7 * 86400;
+                                               my $oldday = POSIX::strftime("%s", 1,1,1,$d,$m-1,$y-1900);
+                                               my $lastday = $oldday;
+                                               if (($saved_last_line{datetime} =~ /^(\d+)\-(\d+)\-(\d+) /) ||
+                                                       ($pgb_saved_last_line{datetime} =~ /^(\d+)\-(\d+)\-(\d+) /)) {
+                                                       $lastday = POSIX::strftime("%s", 1,1,1,$3,$2-1,$1-1900);
+                                               }
+                                               if (($lastday - $oldday) > $diff_day) {
                                                        &logmsg('DEBUG', "Removing obsolete directory $outdir/$y/$m/$d");
                                                        &cleanup_directory("$outdir/$y/$m/$d", 1);
                                                        push(@rmdays, $d);
@@ -2485,9 +2492,7 @@ sub process_file
                        if ($has_exclusion >= 0) {
 
                                # Log line matches the excluded regex
-                               my $ef = 0;
-                               map { $ef = 1, last if ($line =~ /$_/is); } @exclude_line;
-                               next if ($ef);
+                               map { next if ($line =~ /$_/is); } @exclude_line;
                        }
 
                        chomp($line);
@@ -2691,9 +2696,7 @@ sub process_file
                        if ($has_exclusion >= 0) {
 
                                # Log line matches the excluded regex
-                               my $ef = 0;
-                               map { $ef = 1, last if ($line =~ /$_/is); } @exclude_line;
-                               next if ($ef);
+                               map { next if ($line =~ /$_/is); } @exclude_line;
                        }
 
                        chomp($line);