From 07e70bb1002db0cf67bd99e42acd7bbb5ede90c4 Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Fri, 2 Aug 2013 17:33:24 +0200 Subject: [PATCH] Fix CSV log parser and add --csv-separator command line option to allow change of the default csv field separator, coma, in any other character. --- pgbadger | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pgbadger b/pgbadger index fdb4321..174e700 100755 --- a/pgbadger +++ b/pgbadger @@ -145,6 +145,7 @@ my $tsung_queries = 0; my $queue_size = 0; my $job_per_file = 0; my $charset = 'utf-8'; +my $csv_sep_char = ','; my $NUMPROGRESS = 10000; my @DIMENSIONS = (800, 300); @@ -244,6 +245,7 @@ my $result = GetOptions( "disable-autovacuum!" => \$disable_autovacuum, "client=s" => \@dbclient2, # Backward compatibility "charset=s" => \$charset, + "csv-separator=s" => \$csv_sep_char, ); die "FATAL: use pgbadger --help\n" if (not $result); @@ -292,6 +294,7 @@ for (my $i = 0 ; $i < 59 ; $i += $avg_minutes) { push(@avgs, 59); # Set error like log level regex +my $parse_regex = qr/^(LOG|WARNING|ERROR|FATAL|PANIC|DETAIL|HINT|STATEMENT|CONTEXT)/; my $full_error_regex = qr/^(WARNING|ERROR|FATAL|PANIC|DETAIL|HINT|STATEMENT|CONTEXT)/; my $main_error_regex = qr/^(WARNING|ERROR|FATAL|PANIC)/; @@ -944,6 +947,7 @@ Options: --disable-checkpoint : do not generate checkpoint/restartpoint report. --disable-autovacuum : do not generate autovacuum report. --charset : used to set the HTML charset to be used. Default: utf-8. + --csv-separator : used to set the CSV field separator, default: , Examples: @@ -1094,7 +1098,7 @@ sub process_file if ($format eq 'csv') { require Text::CSV_XS; - my $csv = Text::CSV_XS->new({binary => 1, eol => $/}); + my $csv = Text::CSV_XS->new({binary => 1, eol => $/, sep_char => $csv_sep_char}); # Parse csvlog lines while (my $row = $csv->getline($lfile)) { @@ -1121,9 +1125,7 @@ sub process_file $cursize = 0; } } - - # Process only relevant lines - next if ($row->[11] !~ $full_error_regex); + next if ($row->[11] !~ $parse_regex); # Extract the date $row->[0] =~ m/^(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)\.(\d+)/; @@ -5523,6 +5525,12 @@ sub parse_query } } + # Apply bind parameters if any + if ($prefix_vars{'t_detail'} =~ /parameters: (.*)/) { + $cur_info{$t_pid}{parameters} = "$1"; + # go look at other params + } + #### # Registrer previous query storage into global statistics before starting to store current query #### -- 2.40.0