From 929437140fa8989add760cdf8bcd2d33735f283f Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Thu, 26 Dec 2013 10:39:15 +0100 Subject: [PATCH] Add -O | --outdir path to specify the directory where out file must be saved. --- README | 1 + doc/pgBadger.pod | 1 + pgbadger | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README b/README index e782547..6447d0a 100644 --- a/README +++ b/README @@ -40,6 +40,7 @@ SYNOPSIS -o | --outfile filename: define the filename for output. Default depends on the output format: out.html, out.txt or out.tsung. To dump output to stdout use - as filename. + -O | --outdir path : directory where out file must be saved. -p | --prefix string : give here the value of your custom log_line_prefix defined in your postgresql.conf. Only use it if you aren't using one of the standard prefixes specified diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index 0dd77dc..f7b205c 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -42,6 +42,7 @@ Options: -o | --outfile filename: define the filename for output. Default depends on the output format: out.html, out.txt or out.tsung. To dump output to stdout use - as filename. + -O | --outdir path : directory where out file must be saved. -p | --prefix string : give here the value of your custom log_line_prefix defined in your postgresql.conf. Only use it if you aren't using one of the standard prefixes specified diff --git a/pgbadger b/pgbadger index 7bd67ff..9a76d9c 100755 --- a/pgbadger +++ b/pgbadger @@ -220,6 +220,7 @@ my $result = GetOptions( "N|appname=s" => \@dbappname, "n|nohighlight!" => \$nohighlight, "o|outfile=s" => \$outfile, + "O|outdir=s" => \$outdir, "p|prefix=s" => \$log_line_prefix, "P|no-prettify!" => \$noprettify, "q|quiet!" => \$quiet, @@ -358,8 +359,17 @@ $img_format = 'png' if ($img_format ne 'jpeg'); # Extract the output directory from outfile so that graphs will # be created in the same directory -my @infs = fileparse($outfile); -$outdir = $infs[1] . '/'; +if ($outfile ne '-') { + if (!$outdir) { + my @infs = fileparse($outfile); + $outdir = $infs[1]; + } elsif (!-d "$outdir") { + # An output directory have been passed as command line parameter + die "FATAL: $outdir is not a directory or doesn't exist.\n"; + } + $outfile = basename($outfile); + $outfile = $outdir . '/' . $outfile; +} # Remove graph support if output is not html $graph = 0 unless ($extension eq 'html' or $extension eq 'binary' ); @@ -915,6 +925,7 @@ Options: -o | --outfile filename: define the filename for the output. Default depends on the output format: out.html, out.txt or out.tsung. To dump output to stdout use - as filename. + -O | --outdir path : directory where out file must be saved. -p | --prefix string : give here the value of your custom log_line_prefix defined in your postgresql.conf. Only use it if you aren't using one of the standard prefixes specified -- 2.40.0