]> granicus.if.org Git - pgbadger/commitdiff
Add -L | --logfile-list command line option to read a list of logfiles from a file...
authorDarold Gilles <gilles@darold.net>
Thu, 5 Mar 2015 16:32:09 +0000 (17:32 +0100)
committerDarold Gilles <gilles@darold.net>
Thu, 5 Mar 2015 16:32:09 +0000 (17:32 +0100)
README
doc/pgBadger.pod
pgbadger

diff --git a/README b/README
index 1cc580073a62fe484f606b1837739e5bb10eb556..23708a2bbc4ceebec3c6150f092b73a73fed5cf0 100644 (file)
--- 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
index 1d021971d24e9e4101726a3937a74a18ab5d8086..eaf84d51dfd3b40f620370a71d9a20d4d587c664 100644 (file)
@@ -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
index 1d2e3267a453ac2c159e899cb878e0b75104032c..efdfcd1f59e3b2232aa40234b8ae2791e726904a 100755 (executable)
--- 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 = <IN>;
+       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