From: Darold Gilles Date: Thu, 18 Oct 2012 21:14:24 +0000 (+0200) Subject: Add -C | --nocomment option to remove comment like /* ... */ from queries. Thanks... X-Git-Tag: v3.2~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0864940a070ef77e0fb2d049e83eb9d0299e5f56;p=pgbadger Add -C | --nocomment option to remove comment like /* ... */ from queries. Thanks to Hubert Depesz Lubaczewski for the feature request. --- diff --git a/README b/README index fb909c1..844069b 100644 --- a/README +++ b/README @@ -17,6 +17,8 @@ SYNOPSIS -a | --average minutes : number of minutes to build the average graphs of queries and connections. -b | --begin datetime : start date/time for the data to be parsed in log. + -c | --dbclient host : only report what concern the given client host. + -C | --nocomment : remove comments like /* ... */ from queries. -d | --dbname database : only report what concern the given database -e | --end datetime : end date/time for the data to be parsed in log. -f | --format logtype : possible values: syslog,stderr,csv. Default: stderr. diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index 7f871ff..001a04d 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -19,6 +19,8 @@ Options: -a | --average minutes : number of minutes to build the average graphs of queries and connections. -b | --begin datetime : start date/time for the data to be parsed in log. + -c | --dbclient host : only report what concern the given client host. + -C | --nocomment : remove comments like /* ... */ from queries. -d | --dbname database : only report what concern the given database -e | --end datetime : end date/time for the data to be parsed in log. -f | --format logtype : possible values: syslog,stderr,csv. Default: stderr. diff --git a/pgbadger b/pgbadger index d8d076a..2aae672 100755 --- a/pgbadger +++ b/pgbadger @@ -95,6 +95,7 @@ my $t_min_hour = 0; my $t_max_hour = 0; my $log_duration = 0; my $enable_log_duration = 0; +my $remove_comment = 0; my $enable_log_min_duration = 0; my $NUMPROGRESS = 10000; @@ -118,6 +119,7 @@ my $result = GetOptions( "a|average=i" => \$avg_minutes, "b|begin=s" => \$from, "c|client=s" => \$dbclient, + "C|nocomment!" => \$remove_comment, "d|dbname=s" => \$dbname, "e|end=s" => \$to, "f|format=s" => \$format, @@ -835,6 +837,7 @@ Options: queries and connections. -b | --begin datetime : start date/time for the data to be parsed in log. -c | --dbclient host : only report what concern the given client host. + -C | --nocomment : remove comments like /* ... */ from queries. -d | --dbname database : only report what concern the given database. -e | --end datetime : end date/time for the data to be parsed in log. -f | --format logtype : possible values: syslog,stderr,csv. Default: stderr. @@ -3514,6 +3517,11 @@ sub store_queries { my $t_pid = shift; + # Remove comments if required + if ($remove_comment) { + $cur_info{$t_pid}{query} =~ s/\/\*(.*?)\*\///gs; + } + # Cleanup and normalize the current query $cur_info{$t_pid}{query} =~ s/^[\t\s]+//s; $cur_info{$t_pid}{query} =~ s/[\t\s]+$//s;