From: Darold Gilles Date: Thu, 5 Mar 2015 16:32:09 +0000 (+0100) Subject: Add -L | --logfile-list command line option to read a list of logfiles from a file... X-Git-Tag: v6.3~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3dc9a2fbd05f62e0fc26e4a351a8df9784aa39d1;p=pgbadger Add -L | --logfile-list command line option to read a list of logfiles from a file. Thanks to Hubert depesz Lubaczewski for the feature request. --- diff --git a/README b/README index 1cc5800..23708a2 100644 --- a/README +++ b/README @@ -11,6 +11,8 @@ SYNOPSIS logfile can be a single log file, a list of files, or a shell command returning a list of files. If you want to pass log content from stdin use - as filename. Note that input from stdin will not work with csvlog. + You can also use a file containing a list of log file to parse, see -L + command line option. Options: @@ -41,6 +43,7 @@ SYNOPSIS last datetime and line parsed. Useful if you want to watch errors since last run or if you want one report per day with a log rotated each week. + -L | logfile-list file : file containing a list of log file to parse. -m | --maxlength size : maximum length of a query, it will be restricted to the given size. Default: no truncate -M | --no-multiline : do not collect multiline statement to avoid garbage diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index 1d02197..eaf84d5 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -13,6 +13,8 @@ Arguments: logfile can be a single log file, a list of files, or a shell command returning a list of files. If you want to pass log content from stdin use - as filename. Note that input from stdin will not work with csvlog. + You can also use a file containing a list of log file to parse, see -L + command line option. Options: @@ -43,6 +45,7 @@ Options: last datetime and line parsed. Useful if you want to watch errors since last run or if you want one report per day with a log rotated each week. + -L | logfile-list file : file containing a list of log file to parse. -m | --maxlength size : maximum length of a query, it will be restricted to the given size. Default: no truncate -M | --no-multiline : do not collect multiline statement to avoid garbage diff --git a/pgbadger b/pgbadger index 1d2e326..efdfcd1 100755 --- a/pgbadger +++ b/pgbadger @@ -235,6 +235,7 @@ my $dns_resolv = 0; my $nomultiline = 0; my $noreport = 0; my $log_duration = 0; +my $logfile_list = ''; my $NUMPROGRESS = 10000; my @DIMENSIONS = (800, 300); @@ -328,6 +329,7 @@ my $result = GetOptions( "j|jobs=i" => \$queue_size, "J|job_per_file=i" => \$job_per_file, "l|last-parsed=s" => \$last_parsed, + "L|logfile-list=s" => \$logfile_list, "m|maxlength=i" => \$maxlength, "M|no-multiline!" => \$nomultiline, "N|appname=s" => \@dbappname, @@ -431,9 +433,48 @@ if ($#ARGV >= 0) { } } } else { + if ($logfile_list) { + die "FATAL: stdin input - can not be used with logfile list (-L).\n"; + } + push(@log_files, $file); + } + } + +} + +if ($logfile_list) { + + if (!-e $logfile_list) { + die "FATAL: logfile list $logfile_list must exist!\n"; + } + if (not open(IN, $logfile_list)) { + die "FATAL: can not read logfile list $logfile_list, $!.\n"; + } + my @files = ; + close(IN); + foreach my $file (@files) { + chomp($file); + $file =~ s/\r//; + if ($file eq '-') { + die "FATAL: stdin input - can not be used with logfile list.\n"; + } + if (!$remote_host) { + die "FATAL: logfile $file must exist!\n" if not -f $file; + if (-z $file) { + print "WARNING: file $file is empty\n"; + next; + } push(@log_files, $file); + } else { + # Get files from remote host + &logmsg('DEBUG', "Looking for remote filename using command: $ssh_command \"ls $file\""); + my @rfiles = `$ssh_command "ls $file"`; + foreach my $f (@rfiles) { + push(@log_files, $f); + } } } + } # Logfile is a mandatory parameter @@ -1593,6 +1634,7 @@ Options: last datetime and line parsed. Useful if you want to watch errors since last run or if you want one report per day with a log rotated each week. + -L | logfile-list file : file containing a list of log file to parse. -m | --maxlength size : maximum length of a query, it will be restricted to the given size. Default: no truncate -M | --no-multiline : do not collect multiline statement to avoid garbage