From: Wesley Bowman Date: Tue, 22 Aug 2017 06:28:42 +0000 (+0200) Subject: Add --include-time option X-Git-Tag: v10.0~38^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e954fd164d9fd323983ea342306a64246f30d31;p=pgbadger Add --include-time option This adds the ability to choose times that you want to see, instead of excluding all the times you do not want to see. This is handy when wanting to view only one or two days from a week's worth of logs (simplifies down from multiple --exlucde-time options to one --include-time) Update the documentation & remove double negative --- diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index e5bf106..e82f3f0 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -122,6 +122,9 @@ Options: --exclude-time regex : any timestamp matching the given regex will be excluded from the report. Example: "2013-04-12 .*" You can use this option multiple times. + --include-time regex : only timestamps matching the given regex will be + included in the report. Example: "2013-04-12 .*" + You can use this option multiple times. --exclude-appname name : exclude entries for the specified application name from report. Example: "pg_dump". --exclude-line regex : pgBadger will start to exclude any log entry that diff --git a/pgbadger b/pgbadger index 070888b..c866316 100755 --- a/pgbadger +++ b/pgbadger @@ -276,6 +276,7 @@ my $progress = 1; my $error_only = 0; my @exclude_query = (); my @exclude_time = (); +my @include_time = (); my $exclude_file = ''; my @include_query = (); my $include_file = ''; @@ -464,6 +465,7 @@ my $result = GetOptions( "disable-autovacuum!" => \$disable_autovacuum, "charset=s" => \$charset, "csv-separator=s" => \$csv_sep_char, + "include-time=s" => \@include_time, "exclude-time=s" => \@exclude_time, 'ssh-command=s' => \$ssh_command, 'ssh-program=s' => \$ssh_bin, @@ -888,6 +890,13 @@ if ($#exclude_time >= 0) { &check_regex($r, '--exclude-time'); } } +# +# Testing regex syntax +if ($#include_time >= 0) { + foreach my $r (@include_time) { + &check_regex($r, '--include-time'); + } +} # Loading included query from file if any if ($include_file) { @@ -1853,6 +1862,9 @@ Options: --exclude-time regex : any timestamp matching the given regex will be excluded from the report. Example: "2013-04-12 .*" You can use this option multiple times. + --include-time regex : only timestamps matching the given regex will be + included in the report. Example: "2013-04-12 .*" + You can use this option multiple times. --exclude-appname name : exclude entries for the specified application name from report. Example: "pg_dump". --exclude-line regex : pgBadger will start to exclude any log entry that @@ -15244,6 +15256,18 @@ sub skip_unwanted_line return 1 if ($found); } + if ($#include_time >= 0) { + my $found = 0; + foreach (@include_time) { + if ($prefix_vars{'t_timestamp'} !~ /$_/) { + $found = 1; + last; + } + } + return 1 if ($found); + } + + return 1 if ($from && ($from gt $prefix_vars{'t_timestamp'})); if ($to && ($to lt $prefix_vars{'t_timestamp'})) {