#
 # http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
 #
-# $Id: privoxy-log-parser.pl,v 1.128 2008/12/06 16:18:41 fk Exp $
+# $Id: privoxy-log-parser.pl,v 1.129 2008/12/14 16:24:53 fk Exp $
 #
 # TODO:
 #       - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
         CGI             => 'light_green',
         Redirect        => 'cyan',
         Error           => 'light_red',
+        Crunch          => 'cyan',
         'Fatal error'   => 'light_red',
         'Gif-Deanimate' => 'blue',
         Force           => 'red',
     return $colour_code;
 }
 
-
 sub get_semantic_html_markup ($) {
 ###############################################################
 # Takes a string and returns a span element
     }
 }
 
-
 sub get_line_end () {
 
     my $line_end = "\n";
     return $code;
 }
 
-
 sub default_colours () {
     # XXX: Properly
     our $bg_code;
     return $result;
 }
 
-
 sub highlight_matched_path ($$) {
 
     my $result = shift; # XXX: Stupid name;
     return $result;
 }
 
-
 sub highlight_url ($) {
 
     my $url = shift;
     return $content;
 }
 
-
 sub handle_loglevel_redirect ($) {
 
     my $c = shift;
     return $content;
 }
 
-
 sub handle_loglevel_request ($) {
 
     my $content = shift;
     return $content;
 }
 
+sub handle_loglevel_crunch ($) {
+
+    my $content = shift;
+    our %h;
+    our %reason_colours;
+
+    # Blocked: ads.example.org/
+
+    # Highlight crunch reason
+    foreach my $reason (keys %reason_colours) {
+        $content =~ s@($reason)@$reason_colours{$reason}$1$h{'Standard'}@g;
+    }
+    # Highlight request URL
+    $content = highlight_matched_pattern($content, 'request_', '(?<= )[^ \[]*$');
+
+    if ($content =~ m/\[too long, truncated\]$/) {
+
+        # Blocked: config.privoxy.org/edit-actions-submit?f=3&v=1176116716&s=7&Submit=Submit\
+        #  [...]&filter... [too long, truncated]
+        $content = highlight_matched_pattern($content, 'request_', '^.*(?=\.\.\. \[too long, truncated\]$)');
+
+    }
+
+    return $content;
+}
+
 sub handle_loglevel_connect ($) {
 
     my $c = shift;
         'Connect'       => \&handle_loglevel_connect,
         'Redirect'      => \&handle_loglevel_redirect,
         'Request'       => \&handle_loglevel_request,
+        'Crunch'        => \&handle_loglevel_crunch,
         'Gif-Deanimate' => \&handle_loglevel_gif_deanimate,
         'Info'          => \&handle_loglevel_info,
         'CGI'           => \&handle_loglevel_cgi,