From: Gilles Darold Date: Mon, 2 Jan 2017 22:23:41 +0000 (+0100) Subject: Fix --exclude-line options and removing of obsolete directory when retention is enabl... X-Git-Tag: v9.1~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=411d8c133300a07096dca91c49b739d18db7c0e9;p=pgbadger Fix --exclude-line options and removing of obsolete directory when retention is enabled and --noreport is used. --- diff --git a/pgbadger b/pgbadger index ae49736..c129dc2 100644 --- 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);