From: Darold Gilles Date: Wed, 2 May 2012 10:54:42 +0000 (+0200) Subject: Fix samples error with normalyzed error instead of real error message X-Git-Tag: v3.2~255 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1190ee00b3a98a0a451c04e58a7484f6324495da;p=pgbadger Fix samples error with normalyzed error instead of real error message --- diff --git a/pgbadger b/pgbadger index 9c01c17..d6dd71c 100755 --- a/pgbadger +++ b/pgbadger @@ -503,16 +503,17 @@ sub set_top_sample # Stores top N error sample queries sub set_top_error_sample { - my ($q, $date, $detail) = @_; + my ($q, $date, $real_error, $detail) = @_; - # always keep the last error messages - if (exists $error_info{$q}{date} && ($#{$error_info{$q}{date}} >= $sample)) { - shift(@{$error_info{$q}{date}}); - shift(@{$error_info{$q}{detail}}); + # Stop when we have our number of samples + if (!exists $error_info{$q}{date} || ($#{$error_info{$q}{date}} < $sample)) { + if (!grep(/\Q$real_error\E/, @{$error_info{$q}{error}})) { + push(@{$error_info{$q}{date}}, $date); + push(@{$error_info{$q}{detail}}, $detail); + push(@{$error_info{$q}{error}}, $real_error); + } } - push(@{$error_info{$q}{date}}, $date); - push(@{$error_info{$q}{detail}}, $detail); } @@ -657,7 +658,7 @@ Report not supported by text format $idx++; } print $fh "\n\n"; - print $fh "Report generated by PgBadger $VERSION. License: GPL v3.\n"; + print $fh "Report generated by PgBadger $VERSION.\n"; } @@ -820,7 +821,7 @@ sub html_footer { print $fh qq{
@@ -1650,7 +1651,7 @@ sub dump_as_html print $fh "
$k
"; print $fh "
"; for (my $i = 0; $i <= $#{$error_info{$k}{date}}; $i++) { - print $fh "
$k
\n"; + print $fh "
$error_info{$k}{error}[$i]
\n"; print $fh "
Detail: $error_info{$k}{detail}[$i]
\n" if ($error_info{$k}{detail}[$i]); } print $fh "
"; @@ -1869,9 +1870,9 @@ sub parse_query # Store normalyzed query samples my $cur_last_log_date = "$cur_info{year}-$cur_info{month}-$cur_info{day} $cur_info{hour}:$cur_info{min}:$cur_info{sec}"; if ($t_loglevel =~ /DETAIL|STATEMENT/) { - &set_top_error_sample($normalized_error, $cur_last_log_date, $t_query); + &set_top_error_sample($normalized_error, $cur_last_log_date, $cur_info{query}, $t_query); } else { - &set_top_error_sample($normalized_error, $cur_last_log_date); + &set_top_error_sample($normalized_error, $cur_last_log_date, $cur_info{query}); } %cur_info = (); return;