]> granicus.if.org Git - pgbadger/commitdiff
Fix samples error with normalyzed error instead of real error message
authorDarold Gilles <gilles@darold.net>
Wed, 2 May 2012 10:54:42 +0000 (12:54 +0200)
committerDarold Gilles <gilles@darold.net>
Wed, 2 May 2012 10:54:42 +0000 (12:54 +0200)
pgbadger

index 9c01c170775f1927c1f2ab931e00097004013d56..d6dd71cac78dc9bc7822ba2e2463649f8075e99c 100755 (executable)
--- 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 <a href=\"https://github.com/dalibo/pgbadger\">PgBadger</a> $VERSION. License: GPL v3.\n";
+       print $fh "Report generated by <a href=\"https://github.com/dalibo/pgbadger\">PgBadger</a> $VERSION.\n";
 
 }
 
@@ -820,7 +821,7 @@ sub html_footer
 {
        print $fh qq{
        <div class="footer">
-               Report generated by <a href="https://github.com/dalibo/pgbadger">PgBadger</a> $VERSION. License: GPL v3.
+               Report generated by <a href="https://github.com/dalibo/pgbadger">PgBadger</a> $VERSION.
        </div>
 </div>
 <div id="littleToc">
@@ -1650,7 +1651,7 @@ sub dump_as_html
                        print $fh "<td><div class=\"error\">$k</div>";
                        print $fh "<input type=\"button\" class=\"examplesButton\" id=\"button_NormalizedErrorsMostFrequentReport_$idx\" name=\"button_NormalizedErrorsMostFrequentReport_$idx\" value=\"Show examples\" onclick=\"javascript:toggle('button_NormalizedErrorsMostFrequentReport_$idx', 'examples_NormalizedErrorsMostFrequentReport_$idx', 'examples');\" /><div id=\"examples_NormalizedErrorsMostFrequentReport_$idx\" class=\"examples\" style=\"display:none;\">";
                        for (my $i = 0; $i <= $#{$error_info{$k}{date}}; $i++) {
-                               print $fh "<div class=\"example$i\" title=\"$error_info{$k}{date}[$i]\">$k</div>\n";
+                               print $fh "<div class=\"example$i\" title=\"$error_info{$k}{date}[$i]\">$error_info{$k}{error}[$i]</div>\n";
                                print $fh "<div class=\"errorInformation\">Detail: $error_info{$k}{detail}[$i]</div>\n" if ($error_info{$k}{detail}[$i]);
                        }
                        print $fh "</div>";
@@ -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;