3 ################################################################################
6 # A parser for Privoxy log messages. For incomplete documentation run
7 # perldoc privoxy-log-parser(.pl), for fancy screenshots see:
9 # http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
11 # $Id: privoxy-log-parser.pl,v 1.57 2009/10/10 05:50:02 fabiankeil Exp $
14 # - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
15 # - create fancy statistics
16 # - grep through Privoxy sources to find unsupported log messages
17 # - hunt down substitutions that match content from variables which
18 # can contain stuff like ()?'[]
19 # - replace $h{'foo'} with h('foo') where possible
20 # - hunt down XXX comments instead of just creating them
21 # - add example log lines for every regex and mark them up for
23 # - Handle incomplete input without Perl warning about undefined variables.
24 # - Use generic highlighting function that takes a regex and the
27 # Copyright (c) 2007-2009 Fabian Keil <fk@fabiankeil.de>
29 # Permission to use, copy, modify, and distribute this software for any
30 # purpose with or without fee is hereby granted, provided that the above
31 # copyright notice and this permission notice appear in all copies.
33 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
34 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
35 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
36 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
37 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
38 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
39 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 ################################################################################
47 PRIVOXY_LOG_PARSER_VERSION => '0.5',
48 # Feel free to mess with these ...
49 DEFAULT_BACKGROUND => 'black', # Choose registered colour (like 'black')
50 DEFAULT_TEXT_COLOUR => 'white', # Choose registered colour (like 'black')
51 HEADER_DEFAULT_COLOUR => 'yellow',
52 REGISTER_HEADERS_WITH_THE_SAME_COLOUR => 1,
54 CLI_OPTION_DEFAULT_TO_HTML_OUTPUT => 0,
55 CLI_OPTION_TITLE => 'Privoxy-Log-Parser in da house',
56 CLI_OPTION_NO_EMBEDDED_CSS => 0,
57 CLI_OPTION_NO_MSECS => 0,
58 CLI_OPTION_NO_SYNTAX_HIGHLIGHTING => 0,
59 CLI_OPTION_ERROR_LOG_FILE => '/var/log/privoxy-log.log',
60 CLI_OPTION_SHOW_INEFFECTIVE_FILTERS => 0,
61 CLI_OPTION_ACCEPT_UNKNOWN_MESSAGES => 0,
62 CLI_OPTION_STATISTICS => 0,
64 SUPPRESS_SUCCEEDED_FILTER_ADDITIONS => 1,
66 SHOW_FILTER_READIN_IN => 0,
67 SUPPRESS_EMPTY_LINES => 1,
68 SUPPRESS_SUCCESSFUL_CONNECTIONS => 1,
69 SUPPRESS_ACCEPTED_CONNECTIONS => 1,
70 SUPPRESS_GIF_NOT_CHANGED => 1,
71 SUPPRESS_NEED_TO_DE_CHUNK_FIRST => 1,
73 DEBUG_HEADER_REGISTERING => 0,
74 DEBUG_HEADER_HIGHLIGHTING => 0,
77 DEBUG_SUPPRESS_LOG_MESSAGES => 0,
79 PUNISH_MISSING_LOG_KNOWLEDGE_WITH_DEATH => 0,
80 PUNISH_MISSING_HIGHLIGHT_KNOWLEDGE_WITH_DEATH => 1,
82 LOG_UNPARSED_LINES_TO_EXTRA_FILE => 0,
84 # You better leave these alone unless you know what you're doing.
85 COLOUR_RESET => "\033[0;0m",
89 sub prepare_our_stuff () {
91 # Syntax Higlight hash
93 'red', 'green', 'brown', 'blue', 'purple', 'cyan',
94 'light_gray', 'light_red', 'light_green', 'yellow',
95 'light_blue', 'pink', 'light_cyan', 'white'
102 Filter => 'purple', # XXX: Used?
103 'Re-Filter' => 'purple',
105 Request => 'light_cyan',
106 CGI => 'light_green',
108 Error => 'light_red',
110 'Fatal error' => 'light_red',
111 'Gif-Deanimate' => 'blue',
113 Writing => 'light_green',
114 # ----------------------
117 request_ => 'brown', # host+path but no protocol
118 'ip-address' => 'yellow',
121 Truncation => 'light_red',
123 Timestamp => 'brown',
124 Crunching => 'light_red',
125 crunched => 'light_red',
126 'Request-Line' => 'pink',
128 destination => 'yellow',
129 'http-version' => 'pink',
130 'crunch-pattern' => 'pink',
135 'program-name' => 'cyan',
138 warning => 'light_red',
139 debug => 'light_red',
143 'status-message' => 'light_cyan',
144 'status-code' => 'yellow',
145 'invalid-request' => 'light_red',
147 error => 'light_red',
148 'rewritten-URL' => 'light_red',
149 'pcrs-delimiter' => 'light_red',
150 'ignored' => 'light_red',
151 'action-bits-update' => 'light_red',
152 'configuration-line' => 'red',
153 'content-type' => 'yellow',
158 # Header colours need their own hash so the keys can be accessed properly
159 our %header_colours = (
160 # Prefilled with headers that should not appear with default header colours
161 Cookie => 'light_red',
162 'Set-Cookie' => 'light_red',
163 Warning => 'light_red',
164 Default => HEADER_DEFAULT_COLOUR,
167 # Crunch reasons need their own hash as well
168 our %reason_colours = (
169 'Unsupported HTTP feature' => 'light_red',
170 Blocked => 'light_red',
171 Untrusted => 'light_red',
172 Redirected => 'green',
173 'CGI Call' => 'white',
174 'DNS failure' => 'red',
175 'Forwarding failed' => 'light_red',
176 'Connection failure' => 'light_red',
177 'Out of memory (may mask other reasons)' => 'light_red',
178 'No reason recorded' => 'light_red',
181 our @time_colours = ('white', 'light_gray');
183 # Translate highlight strings into highlight code
184 prepare_highlight_hash(\%header_colours);
185 prepare_highlight_hash(\%reason_colours);
186 prepare_highlight_hash(\%h);
187 prepare_colour_array(\@all_colours);
188 prepare_colour_array(\@time_colours);
195 ###############################################################
196 # Takes a colour string and returns an ANSI escape sequence
197 # (unless --no-syntax-highlighting is used).
198 # XXX: The Rolling Stones reference has to go.
199 ###############################################################
201 my $colour = shift @_;
203 return "" if cli_option_is_set('no-syntax-highlighting');
245 my $bg_code = get_background();
247 our $default = default_colours();
249 if (defined($text{$colour})) {
250 $colour_code = ESCAPE;
251 $colour_code .= $text{$colour};
253 $colour_code .= $light{$colour} ? "1" : "2";
255 $colour_code .= $bg_code;
257 debug_message $colour . " is \'" . $colour_code . $colour . $default . "\'" if DEBUG_PAINT_IT;
259 } elsif ($colour =~ /reset/) {
261 $colour_code = default_colours();
265 die "What's $colour supposed to mean?\n";
271 sub get_semantic_html_markup ($) {
272 ###############################################################
273 # Takes a string and returns a span element
274 ###############################################################
279 if ($type =~ /Standard/) {
283 $code = '<span title="' . $type . '" class="' . $type . '">';
289 sub cli_option_is_set ($) {
292 my $cli_option = shift;
294 die "Unknown CLI option: $cli_option" unless defined $cli_options{$cli_option};
296 return $cli_options{$cli_option};
299 sub get_html_title () {
302 return $cli_options{'title'};
306 sub init_css_colours() {
314 purple => "F06", # XXX: wrong
315 cyan => "F09", # XXX: wrong
320 light_green => "33F",
329 sub get_css_colour ($) {
334 die "What's $colour supposed to mean?\n" unless defined($css_colours{$colour});
336 return '#' . $css_colours{$colour};
339 sub get_css_line ($) {
346 $css_line .= '.' . lc($class) . ' {'; # XXX: lc() shouldn't be necessary
347 die "What's $class supposed to mean?\n" unless defined($h_colours{$class});
348 $css_line .= 'color:' . get_css_colour($h_colours{$class}) . ';';
349 $css_line .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
350 $css_line .= '}' . "\n";
355 sub get_css_line_for_colour ($) {
362 $css_line .= '.' . lc($colour) . ' {'; # XXX: lc() shouldn't be necessary
363 $css_line .= 'color:' . get_css_colour($colour) . ';';
364 $css_line .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
365 $css_line .= '}' . "\n";
370 # XXX: Wrong solution
371 sub get_missing_css_lines () {
375 $css_line .= '.' . 'default' . ' {';
376 $css_line .= 'color:' . HEADER_DEFAULT_COLOUR . ';';
377 $css_line .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
378 $css_line .= '}' . "\n";
386 our %css_colours; #XXX: Wrong solution
390 $css .= '.privoxy-log {';
391 $css .= 'color:' . get_css_colour(DEFAULT_TEXT_COLOUR) . ';';
392 $css .= 'background-color:' . get_css_colour(DEFAULT_BACKGROUND) . ';';
395 foreach my $key (keys %h_colours) {
397 next if ($h_colours{$key} =~ m/reset/); #XXX: Wrong solution.
398 $css .= get_css_line($key);
402 foreach my $colour (keys %css_colours) {
404 $css .= get_css_line_for_colour($colour);
408 $css .= get_missing_css_lines(); #XXX: Wrong solution
417 if (cli_option_is_set('html-output')) {
419 my $title = get_html_title();
421 $intro .= '<html><head>';
422 $intro .= '<title>' . $title . '</title>';
423 $intro .= '<style>' . get_css() . '</style>' unless cli_option_is_set('no-embedded-css');
424 $intro .= '</head><body>';
425 $intro .= '<h1>' . $title . '</h1><p class="privoxy-log">';
435 if (cli_option_is_set('html-output')) {
437 $outro = '</p></body></html>';
443 sub get_line_end () {
447 $line_end = '<br>' . $line_end if cli_option_is_set('html-output');
452 sub get_colour_html_markup ($) {
453 ###############################################################
454 # Takes a colour string a span element. XXX: WHAT?
455 # XXX: This function shouldn't be necessary, the
456 # markup should always be semantically correct.
457 ###############################################################
462 if ($type =~ /Standard/) {
465 $code = '<span class="' . lc($type) . '">';
471 sub default_colours () {
474 return reset_colours();
477 sub show_colours () {
481 sub reset_colours () {
482 return ESCAPE . "0m";
485 sub set_background ($){
501 if (defined($backgrounds{$colour})) {
502 $bg_code = $backgrounds{$colour};
504 die "Invalid background colour: " . $colour;
508 sub get_background (){
512 sub prepare_highlight_hash ($) {
515 if (!cli_option_is_set('html-output')) {
517 foreach my $key (keys %$ref) {
518 $$ref{$key} = paint_it($$ref{$key});
523 foreach my $key (keys %$ref) {
524 $$ref{$key} = get_semantic_html_markup($key);
530 sub prepare_colour_array ($) {
533 if (!cli_option_is_set('html-output')) {
535 foreach my $i (0 ... @$ref - 1) {
536 $$ref[$i] = paint_it($$ref[$i]);
541 foreach my $i (0 ... @$ref - 1) {
542 $$ref[$i] = get_colour_html_markup($$ref[$i]);
548 sub found_unknown_content ($) {
556 return if cli_option_is_set('accept-unknown-messages');
558 return if ($unknown =~ /\[too long, truncated\]$/);
560 $message = "found_unknown_content: Don't know how to highlight: ";
561 # Break line so the log file can later be parsed as Privoxy log file again
562 $message .= '"' . $unknown . '"' . " in:\n";
563 $message .= $req{$t}{'log-message'};
564 debug_message($message);
565 log_parse_error($req{$t}{'log-message'});
567 die "Unworthy content parser" if PUNISH_MISSING_LOG_KNOWLEDGE_WITH_DEATH;
570 sub log_parse_error ($) {
574 if (LOG_UNPARSED_LINES_TO_EXTRA_FILE) {
575 open(ERRORLOG, ">>" . ERROR_LOG_FILE) || die "Writing " . ERROR_LOG_FILE . " failed";
576 print ERRORLOG $message;
581 sub debug_message (@) {
585 print $h{'debug'} . "@message" . $h{'Standard'} . "\n";
588 ################################################################################
589 # highlighter functions that aren't loglevel-specific
590 ################################################################################
594 # Get highlight marker
596 my $highlight = shift; # XXX: Stupid name;
600 if (defined($highlight)) {
602 $result = $h{$highlight};
606 $message = "h: Don't recognize highlighter $highlight.";
607 debug_message($message);
608 log_parser_error($message);
609 die "Unworthy highlighter function" if PUNISH_MISSING_HIGHLIGHT_KNOWLEDGE_WITH_DEATH;
615 sub highlight_known_headers ($) {
620 my $headers = join ('|', keys %header_colours);
622 debug_message("Searching $content for things to highlight.") if DEBUG_HEADER_HIGHLIGHTING;
624 if ($content =~ m/(?<=\s)($headers):/) {
626 $content =~ s@(?<=[\s|'])($header)(?=:)@$header_colours{$header}$1$h{'Standard'}@ig;
627 debug_message("Highlighted $content") if DEBUG_HEADER_HIGHLIGHTING;
633 sub highlight_matched_request_line ($$) {
635 my $result = shift; # XXX: Stupid name;
637 if ($result =~ m@(.*)($regex)(.*)@) {
638 $result = $1 . highlight_request_line($2) . $3
643 sub highlight_request_line ($) {
646 my ($method, $url, $http_version);
649 #GET http://images.sourceforge.net/sfx/icon_warning.gif HTTP/1.1
650 if ($rl =~ m/Invalid request/) {
652 $rl = h('invalid-request') . $rl . h('Standard');
654 } elsif ($rl =~ m/^([-\w]+) (.*) (HTTP\/\d\.\d)/) {
656 # XXX: might not match in case of HTTP method fuzzing.
657 # XXX: save these: ($method, $path, $http_version) = ($1, $2, $3);
658 $rl =~ s@^(\w+)@$h{'method'}$1$h{'Standard'}@;
659 if ($rl =~ /http:\/\//) {
660 $rl = highlight_matched_url($rl, '[^\s]*(?=\sHTTP)');
662 $rl = highlight_matched_pattern($rl, 'request_', '[^\s]*(?=\sHTTP)');
665 $rl =~ s@(HTTP\/\d\.\d)$@$h{'http-version'}$1$h{'Standard'}@;
667 } elsif ($rl =~ m/\.\.\. \[too long, truncated\]$/) {
669 $rl =~ s@^(\w+)@$h{'method'}$1$h{'Standard'}@;
670 $rl = highlight_matched_url($rl, '[^\s]*(?=\.\.\.)');
672 } elsif ($rl =~ m/^ $/) {
674 $rl = h('error') . "No request line specified!" . h('Standard');
678 debug_message ("Can't parse request line: $rl");
685 sub highlight_response_line ($) {
688 my ($http_version, $status_code, $status_message);
693 # TODO: Mark different status codes differently
695 if ($rl =~ m/((?:HTTP\/\d\.\d|ICY)) (\d+) (.*)/) {
696 ($http_version, $status_code, $status_message) = ($1, $2, $3);
698 debug_message ("Can't parse response line: $rl") and die 'Fix this';
701 # Rebuild highlighted
703 $rl .= h('http-version') . $http_version . h('Standard');
705 $rl .= h('status-code') . $status_code . h('Standard');
707 $rl .= h('status-message') . $status_message . h('Standard');
712 sub highlight_matched_url ($$) {
714 my $result = shift; # XXX: Stupid name;
717 #print "Got $result, regex ($regex)\n";
719 if ($result =~ m@(.*?)($regex)(.*)@) {
720 $result = $1 . highlight_url($2) . $3;
721 #print "Now the result is $result\n";
727 sub highlight_matched_host ($$) {
729 my $result = shift; # XXX: Stupid name;
732 if ($result =~ m@(.*?)($regex)(.*)@) {
733 $result = $1 . h('host') . $2 . h('Standard') . $3;
739 sub highlight_matched_pattern ($$$) {
742 my $result = shift; # XXX: Stupid name;
746 die "Unknown key $key" unless defined $h{$key};
748 if ($result =~ m@(.*?)($regex)(.*)@) {
749 $result = $1 . h($key) . $2 . h('Standard') . $3;
755 sub highlight_matched_path ($$) {
757 my $result = shift; # XXX: Stupid name;
760 if ($result =~ m@(.*?)($regex)(.*)@) {
761 $result = $1 . h('path') . $2 . h('Standard') . $3;
767 sub highlight_url ($) {
771 if (cli_option_is_set('html-output')) {
773 $url = '<a href="' . $url . '">' . $url . '</a>';
777 $url = h('URL') . $url . h('Standard');
784 ################################################################################
785 # loglevel-specific highlighter functions
786 ################################################################################
788 sub handle_loglevel_header ($) {
797 our $header_colour_index;
798 our $no_special_header_highlighting;
800 # Register new headers
801 # scan: Accept: image/png,image/*;q=0.8,*/*;q=0.5
802 if ($c =~ m/^scan: ((?>[^:]+)):/) {
804 if (!defined($header_colours{$header}) and $header =~ /^[\d\w-]*$/) {
805 debug_message "Registering previously unknown header $1" if DEBUG_HEADER_REGISTERING;
807 if (REGISTER_HEADERS_WITH_THE_SAME_COLOUR) {
808 $header_colours{$header} = $header_colours{'Default'};
810 $header_colours{$header} = $all_colours[$header_colour_index % @all_colours];
811 $header_colour_index++;
816 if ($c =~ m/^scan: ((\w*) (.*) (HTTP\/\d\.\d))/) {
818 # Client request line
819 # Save for statistics (XXX: Not implemented yet)
820 $req{$t}{'method'} = $2;
821 $req{$t}{'destination'} = $3;
822 $req{$t}{'http-version'} = $4;
824 $content = highlight_request_line($1);
826 } elsif ($c =~ m/^(scan: )((?:HTTP\/\d\.\d|ICY) (\d+) (.*))/) {
828 # Server response line
829 $req{$t}{'response_line'} = $2;
830 $req{$t}{'status_code'} = $3;
831 $req{$t}{'status_message'} = $4;
832 $content = $1 . highlight_response_line($req{$t}{'response_line'});
834 } elsif ($c =~ m/^Crunching (?:server|client) header: .* \(contains: ([^\)]*)\)/) {
836 # Crunching server header: Set-Cookie: trac_form_token=d5308c34e16d15e9e301a456; (contains: Cookie:)
837 $content =~ s@(?<=contains: )($1)@$h{'crunch-pattern'}$1$h{'Standard'}@;
838 $content =~ s@(Crunching)@$h{$1}$1$h{'Standard'}@;
840 } elsif ($c =~ m/^New host is: ([^\s]*)\./) {
842 # New host is: trac.vidalia-project.net. Crunching Referer: http://www.vidalia-project.net/
843 $c = highlight_matched_host($c, '(?<=New host is: )[^\s]+');
844 $content = highlight_matched_url($c, '(?<=Crunching Referer: )[^\s]+');
846 } elsif ($c =~ m/^Text mode enabled by force. (Take cover)!/) {
848 # Text mode enabled by force. Take cover!
849 $content =~ s@($1)@$h{'warning'}$1$h{'Standard'}@;
851 } elsif ($c =~ m/^(New HTTP Request-Line: )(.*)/) {
853 # New HTTP Request-Line: GET http://www.privoxy.org/ HTTP/1.1
854 $content = $1 . highlight_request_line($2);
856 } elsif ($c =~ m/^Adjust(ed)? Content-Length to \d+/) {
858 # Adjusted Content-Length to 2132
859 # Adjust Content-Length to 33533
860 $content =~ s@(?<=Content-Length to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
861 $content = highlight_known_headers($content);
863 } elsif ($c =~ m/^Destination extracted from "Host:" header. New request URL:/) {
865 # Destination extracted from "Host:" header. New request URL: http://www.cccmz.de/~ridcully/blog/
866 $content = highlight_matched_url($content, '(?<=New request URL: ).*');
868 } elsif ($c =~ m/^Couldn\'t parse:/) {
870 # XXX: These should probable be logged with LOG_LEVEL_ERROR
871 # Couldn't parse: If-Modified-Since: Wed, 21 Mar 2007 16:34:50 GMT (crunching!)
872 # Couldn't parse: at, 24 Mar 2007 13:46:21 GMT in If-Modified-Since: Sat, 24 Mar 2007 13:46:21 GMT (crunching!)
873 $content =~ s@^(Couldn\'t parse)@$h{'error'}$1$h{'Standard'}@;
875 } elsif ($c =~ /^Tagger \'([^\']*)\' added tag \'([^\']*)\'/ or
876 $c =~ m/^Adding tag \'([^\']*)\' created by header tagger \'([^\']*)\'/) {
878 # Adding tag 'GET request' created by header tagger 'method-man' (XXX: no longer used)
879 # Tagger 'revalidation' added tag 'REVALIDATION-REQUEST'. No action bit update necessary.
880 # Tagger 'revalidation' added tag 'REVALIDATION-REQUEST'. Action bits updated accordingly.
882 # XXX: Save tag and tagger
884 $content =~ s@(?<=^Tagger \')([^\']*)@$h{'tagger'}$1$h{'Standard'}@;
885 $content =~ s@(?<=added tag \')([^\']*)@$h{'tag'}$1$h{'Standard'}@;
886 $content =~ s@(?<=Action bits )(updated)@$h{'action-bits-update'}$1$h{'Standard'}@;
887 $no_special_header_highlighting = 1;
889 } elsif ($c =~ /^Tagger \'([^\']*)\' didn['']t add tag \'([^\']*)\'/) {
891 # Tagger 'revalidation' didn't add tag 'REVALIDATION-REQUEST'. Tag already present
892 # XXX: Save tag and tagger
894 $content =~ s@(?<=^Tagger \')([^\']*)@$h{'tag'}$1$h{'Standard'}@;
895 $content =~ s@(?<=didn['']t add tag \')([^\']*)@$h{'tagger'}$1$h{'Standard'}@;
897 } elsif ($c =~ m/^(?:scan:|Randomiz|addh:|Adding:|Removing:|Referer:|Modified:|Accept-Language header|[Cc]ookie)/
898 or $c =~ m/^(Text mode is already enabled|Denied request with NULL byte|Replaced:|add-unique:)/
899 or $c =~ m/^(Crunched (incoming|outgoing) cookie|Suppressed offer|Accepted the client)/
900 or $c =~ m/^(addh-unique|Referer forged to)/
901 or $c =~ m/^Downgraded answer to HTTP\/1.0/
902 or $c =~ m/^Parameter: \+hide-referrer\{[^\}]*\} is a bad idea, but I don\'t care./
903 or $c =~ m/^Referer (?:overwritten|replaced) with: Referer: / #XXX: should this be highlighted?
904 or $c =~ m/^Referer crunched!/
905 or $c =~ m/^crunched x-forwarded-for!/
906 or $c =~ m/^crunched From!/
907 or $c =~ m/^ modified$/
908 or $c =~ m/^Content filtering is enabled. Crunching:/
909 or $c =~ m/^force-text-mode overruled the client/
910 or $c =~ m/^Server time in the future\./
911 or $c =~ m/^content-disposition header crunched and replaced with:/i
912 or $c =~ m/^Reducing white space in /
913 or $c =~ m/^Ignoring single quote in /
914 or $c =~ m/^Converting tab to space in /
915 or $c =~ m/A HTTP\/1\.1 response without/
916 or $c =~ m/Disabled filter mode on behalf of the client/
917 or $c =~ m/Keeping the (?:server|client) header /
918 or $c =~ m/Content modified with no Content-Length header set/
919 or $c =~ m/^Appended client IP address to/
920 or $c =~ m/^Removing 'Connection: close' to imply keep-alive./
921 or $c =~ m/^keep-alive support is disabled/
924 # XXX: Some of these may need highlighting
926 # Modified: User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; pl-PL; rv:1.8.1.1) Gecko/20070214 Firefox/2.0.0.1
927 # Accept-Language header crunched and replaced with: Accept-Language: pl-pl
928 # cookie 'Set-Cookie: eZSessionCookie=07bfec287c197440d299f81580593c3d; \
929 # expires=Thursday, 12-Apr-07 15:16:18 GMT; path=/' send by \
930 # http://wirres.net/article/articleview/4265/1/6/ appears to be using time format 1 (XXX: gone with the wind)
931 # Cookie rewritten to a temporary one: Set-Cookie: NSC_gffe-iuuq-mc-wtfswfs=8efb33a53660;path=/
932 # Text mode is already enabled
933 # Denied request with NULL byte(s) turned into line break(s)
934 # Replaced: 'Connection: Yo, home to Bel Air' with 'Connection: close'
935 # addh-unique: Host: people.freebsd.org
936 # Suppressed offer to compress content
937 # Crunched incoming cookie -- yum!
938 # Accepted the client's request to fetch without filtering.
939 # Crunched outgoing cookie: Cookie: PREF=ID=6cf0abd347b30262:TM=1173357617:LM=1173357617:S=jZypyyJ7LPiwFi1_
940 # addh-unique: Host: subkeys.pgp.net:11371
941 # Referer forged to: Referer: http://10.0.0.1/
942 # Downgraded answer to HTTP/1.0
943 # Parameter: +hide-referrer{pille-palle} is a bad idea, but I don't care.
944 # Referer overwritten with: Referer: pille-palle
945 # Referer replaced with: Referer: pille-palle
946 # crunched x-forwarded-for!
948 # modified # XXX: pretty stupid log message
949 # Content filtering is enabled. Crunching: 'Range: 1234-5678' to prevent range-mismatch problems
950 # force-text-mode overruled the client's request to fetch without filtering!
951 # Server time in the future.
952 # content-disposition header crunched and replaced with: content-disposition: filename=baz
953 # Content-Disposition header crunched and replaced with: content-disposition: filename=baz
954 # Reducing white space in 'X-LWS-Test: "This is quoted" this is not "this is " but " this again is not'
955 # Ignoring single quote in 'X-LWS-Test: "This is quoted" this is not "this is " but " this again is not'
956 # Converting tab to space in 'X-LWS-Test: "This is quoted" this is not "this is " but "\
958 # A HTTP/1.1 response without Connection header implies keep-alive.
959 # Disabled filter mode on behalf of the client.
960 # Keeping the server header 'Connection: keep-alive' around.
961 # Keeping the client header 'Connection: close' around. The connection will not be kept alive.
962 # Keeping the client header 'Connection: keep-alive' around. The connection will be kept alive if possible.
963 # Content modified with no Content-Length header set. Creating a fake one for adjustment later on.
964 # Appended client IP address to X-Forwarded-For: 10.0.0.2, 10.0.0.1
965 # Removing 'Connection: close' to imply keep-alive.
966 # keep-alive support is disabled. Crunching: Keep-Alive: 300.
968 } elsif ($c =~ m/^scanning headers for:/) {
970 return '' unless SHOW_SCAN_INTRO;
972 } elsif ($c =~ m/^[Cc]runch(ing|ed)|crumble crunched:/) {
973 # crunched User-Agent!
974 # Crunching: Content-Encoding: gzip
976 $content =~ s@(Crunching|crunched)@$h{$1}$1$h{'Standard'}@;
978 } elsif ($c =~ m/^Offending request data with NULL bytes turned into \'°\' characters:/) {
980 # Offending request data with NULL bytes turned into '°' characters: °°n°°(°°°
982 $content = h('warning') . $content . h('Standard');
984 } elsif ($c =~ m/^(Transforming \")(.*?)(\" to \")(.*?)(\")/) {
986 # Transforming "Proxy-Authenticate: Basic realm="Correos Proxy Server"" to\
987 # "Proxy-Authenticate: Basic realm="Correos Proxy Server""
989 $content =~ s@(?<=^Transforming \")(.*)(?=\" to)@$h{'Header'}$1$h{'Standard'}@;
990 $content =~ s@(?<=to \")(.*)(?=\")@$h{'Header'}$1$h{'Standard'}@;
992 } elsif ($c =~ m/^Removing empty header/) {
994 # Removing empty header
997 } elsif ($c =~ m/^Content-Type: .* not replaced/) {
999 # Content-Type: application/octet-stream not replaced. It doesn't look like text.\
1000 # Enable force-text-mode if you know what you're doing.
1001 # XXX: Could highlight more here.
1002 $content =~ s@(?<=^Content-Type: )(.*)(?= not replaced)@$h{'content-type'}$1$h{'Standard'}@;
1004 } elsif ($c =~ m/^(Server|Client) keep-alive timeout is/) {
1006 # Server keep-alive timeout is 5. Sticking with 10.
1007 # Client keep-alive timeout is 20. Sticking with 10.
1009 $content =~ s@(?<=timeout is )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1010 $content =~ s@(?<=Sticking with )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1012 } elsif ($c =~ m/^Reducing keep-alive timeout/) {
1014 # Reducing keep-alive timeout from 60 to 10.
1016 $content =~ s@(?<= from )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1017 $content =~ s@(?<= to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1021 found_unknown_content($content);
1025 unless ($c =~ m/^Transforming/) {
1026 $content = highlight_known_headers($content) unless $no_special_header_highlighting;
1032 sub handle_loglevel_re_filter ($) {
1034 my $content = shift;
1040 our %header_colours;
1042 our $header_colour_index;
1045 and $c =~ m/^(?:re_)?filtering \'?(.*?)\'? \(size (\d*)\) with (?:filter )?\'?([^\s]*?)\'? ?\.{3}$/) {
1047 # Used by Privoxy 3.0.5 and 3.0.6:
1049 # Used by Privoxy 3.0.7:
1050 # filtering 'Connection: close' (size 17) with 'generic-content-ads' ...
1052 $req{$t}{'filtered_header'} = $1;
1053 $req{$t}{'old_header_size'} = $2;
1054 $req{$t}{'header_filter_name'} = $3;
1056 unless (cli_option_is_set('show-ineffective-filters') or
1057 $req{$t}{'header_filter_name'} =~ m/^privoxy-filter-test$/) {
1060 $content =~ s@(?<=\(size )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1061 $content =~ s@($req{$t}{'header_filter_name'})@$h{'filter'}$1$h{'Standard'}@;
1063 } elsif ($c =~ m/^ ?\.\.\. ?produced (\d*) hits \(new size (\d*)\)\./) {
1065 # ...produced 0 hits (new size 23).
1066 #... produced 1 hits (new size 54).
1068 $req{$t}{'header_filter_hits'} = $1;
1069 $req{$t}{'new_header_size'} = $2;
1071 unless (cli_option_is_set('show-ineffective-filters') or
1072 (defined($req{$t}{'header_filter_name'}) and
1073 $req{$t}{'header_filter_name'} =~ m/^privoxy-filter-test$/)) {
1075 if ($req{$t}{'header_filter_hits'} == 0 and
1076 not (defined($req{$t}{'header_filter_name'}) and
1077 $req{$t}{'header_filter_name'} =~ m/^privoxy-filter-test$/)) {
1080 # Reformat including information from the intro
1081 $c = "'" . h('filter') . $req{$t}{'header_filter_name'} . h('Standard') . "'";
1083 # XXX: Hide behind constant, it may be interesting if LOG_LEVEL_HEADER isn't enabled as well.
1084 # $c .= $req{$t}{'filtered_header'} . " ";
1085 $c .= h('Number') . $req{$t}{'header_filter_hits'}. h('Standard');
1086 $c .= ($req{$t}{'header_filter_hits'} == 1) ? " time, " : " times, ";
1088 if ($req{$t}{'old_header_size'} != $req{$t}{'new_header_size'}) {
1090 $c .= "changing size from ";
1091 $c .= h('Number') . $req{$t}{'old_header_size'} . h('Standard');
1093 $c .= h('Number') . $req{$t}{'new_header_size'} . h('Standard');
1098 $c .= "keeping the size at " . $req{$t}{'old_header_size'};
1102 # Highlight from last line (XXX: What?)
1103 # $c =~ s@(?<=produced )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1104 # $c =~ s@($req{$t}{'header_filter_name'})@$h{'filter'}$1$h{'Standard'}@;
1109 $c =~ s@(?<=produced )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1110 $c =~ s@(?<=new size )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1115 } elsif ($c =~ m/^(Tagger|Filter) ([^\s]*) has empty joblist. Nothing to do./) {
1117 # Filter privoxy-filter-test has empty joblist. Nothing to do.
1118 # Tagger variable-test has empty joblist. Nothing to do.
1120 $content =~ s@(?<=$1 )([^\s]*)@$h{'filter'}$1$h{'Standard'}@;
1122 } elsif ($c =~ m/^(?:re_)?filtering ([^\s]+) \(size (\d+)\) with (?:filter )?\'?([^\s]+?)\'? produced (\d+) hits \(new size (\d+)\)/) {
1124 # XXX: only the second version gets highlighted properly.
1125 # re_filtering www.lfk.de/favicon.ico (size 209) with filter untrackable-hulk produced 0 hits (new size 209).
1126 # filtering aci.blogg.de/ (size 37988) with 'blogg.de' produced 3 hits (new size 38057)
1127 $req{$t}{'content_source'} = $1;
1128 $req{$t}{'content_size'} = $2;
1129 $req{$t}{'content_filter'} = $3;
1130 $req{$t}{'content_hits'} = $4;
1131 $req{$t}{'new_content_size'} = $5;
1132 $req{$t}{'content_size_change'} = $req{$t}{'new_content_size'} - $req{$t}{'content_size'};
1133 #return '' if ($req{$t}{'content_hits'} == 0 && !cli_option_is_set('show-ineffective-filters'));
1134 if ($req{$t}{'content_hits'} == 0 and
1135 not (cli_option_is_set('show-ineffective-filters')
1136 or ($req{$t}{'content_filter'} =~ m/^privoxy-filter-test$/))) {
1140 $c =~ s@(?<=\(size )(\d+)\)(?= with)@$h{'Number'}$1$h{'Standard'}@;
1141 $c =~ s@(?<=\(new size )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1142 $c =~ s@(?<=produced )(\d+)(?= hits)@$h{'Number'}$1$h{'Standard'}@;
1144 $c =~ s@([^\s]+?)(\'? produced)@$h{'filter'}$1$h{'Standard'}$2@;
1145 $c = highlight_matched_host($c, '(?<=filtering )[^\s]+');
1148 $c .= "(" . $h{'Number'};
1149 $c .= "+" if ($req{$t}{'content_size_change'} >= 0);
1150 $c .= $req{$t}{'content_size_change'} . $h{'Standard'} . ")";
1153 } elsif ($c =~ m/^De-chunking successful. Shrunk from (\d+) to (\d+)/) {
1155 $req{$t}{'chunked-size'} = $1;
1156 $req{$t}{'dechunked-size'} = $2;
1157 $req{$t}{'dechunk-change'} = $req{$t}{'dechunked-size'} - $req{$t}{'chunked-size'};
1159 $content .= " (" . h('Number') . $req{$t}{'dechunk-change'} . h('Standard') . ")";
1161 $content =~ s@(?<=from )($req{$t}{'chunked-size'})@$h{'Number'}$1$h{'Standard'}@;
1162 $content =~ s@(?<=to )($req{$t}{'dechunked-size'})@$h{'Number'}$1$h{'Standard'}@;
1164 } elsif ($c =~ m/^Decompression successful. Old size: (\d+), new size: (\d+)./) {
1166 # Decompression successful. Old size: 670, new size: 1166.
1168 $req{$t}{'size-compressed'} = $1;
1169 $req{$t}{'size-decompressed'} = $2;
1170 $req{$t}{'decompression-gain'} = $req{$t}{'size-decompressed'} - $req{$t}{'size-compressed'};
1172 $content =~ s@(?<=Old size: )($req{$t}{'size-compressed'})@$h{'Number'}$1$h{'Standard'}@;
1173 $content =~ s@(?<=new size: )($req{$t}{'size-decompressed'})@$h{'Number'}$1$h{'Standard'}@;
1175 # XXX: Create sub get_percentage()
1176 if ($req{$t}{'size-decompressed'}) {
1177 $req{$t}{'decompression-gain-percent'} =
1178 $req{$t}{'decompression-gain'} / $req{$t}{'size-decompressed'} * 100;
1180 $content .= " (saved: ";
1181 #$content .= h('Number') . $req{$t}{'decompression-gain'} . h('Standard');
1183 $content .= h('Number') . sprintf("%.2f%%", $req{$t}{'decompression-gain-percent'}) . h('Standard');
1187 } elsif ($c =~ m/^(Need to de-chunk first)/) {
1189 # Need to de-chunk first
1190 return '' if SUPPRESS_NEED_TO_DE_CHUNK_FIRST;
1192 } elsif ($c =~ m/^(Adding (?:dynamic )?re_filter job)/) {
1194 return '' if (SUPPRESS_SUCCEEDED_FILTER_ADDITIONS && m/succeeded/);
1196 # Adding re_filter job ...
1197 # Adding dynamic re_filter job s@^(?:\w*)\s+.*\s+HTTP/\d\.\d\s*@IP-ADDRESS: $origin@D\
1198 # to filter client-ip-address succeeded.
1200 } elsif ($c =~ m/^Reading in filter/) {
1202 return '' unless SHOW_FILTER_READIN_IN;
1206 found_unknown_content($content);
1213 sub handle_loglevel_redirect ($) {
1220 if ($c =~ m/^Decoding "([^""]*)"/) {
1222 $req{$t}{'original-destination'} = $1;
1223 $c = highlight_matched_path($c, '(?<=Decoding ")[^"]*');
1226 } elsif ($c =~ m/^Checking/) {
1228 # Checking /_ylt=A0geu.Z76BRGR9k/**http://search.yahoo.com/search?p=view+odb+presentation+on+freebsd\
1229 # &ei=UTF-8&xargs=0&pstart=1&fr=moz2&b=11 for redirects.
1231 # TODO: Change colour if really url-decoded
1232 $req{$t}{'decoded-original-destination'} = $1;
1233 $c = highlight_matched_path($c, '(?<=Checking ")[^"]*');
1236 } elsif ($c =~ m/^pcrs command "([^""]*)" changed "([^""]*)" to "([^""]*)" \((\d+) hits?\)/) {
1238 # pcrs command "s@&from=rss@@" changed "http://it.slashdot.org/article.pl?sid=07/03/02/1657247&from=rss"\
1239 # to "http://it.slashdot.org/article.pl?sid=07/03/02/1657247" (1 hit).
1241 my ($pcrs_command, $url_before, $url_after, $hits) = ($1, $2, $3, $4); # XXX: save these?
1243 $c =~ s@(?<=pcrs command )"([^""]*)"@$h{'filter'}$1$h{'Standard'}@;
1244 $c = highlight_matched_url($c, '(?<=changed ")[^""]*');
1245 $c =~ s@(?<=changed )"([^""]*)"@$1@; # Remove quotes
1246 $c = highlight_matched_url($c, '(?<=to ")[^""]*');
1247 $c =~ s@(?<=to )"([^""]*)"@$1@; # Remove quotes
1248 $c =~ s@(\d+)(?= hits?)@$h{'hits'}$1$h{'Standard'}@;
1250 } elsif ($c =~ m/(^New URL is: )(.*)/) {
1252 # New URL is: http://it.slashdot.org/article.pl?sid=07/03/04/1511210
1253 # XXX: Use URL highlighter
1255 $c = $1 . h('rewritten-URL') . $2 . h('Standard');
1257 } elsif ($c =~ m/No pcrs command recognized, assuming that/) {
1258 # No pcrs command recognized, assuming that "http://config.privoxy.org/user-manual/favicon.png"\
1259 # is already properly formatted.
1260 # XXX: assume the same?
1261 $c = highlight_matched_url($c, '(?<=assuming that \")[^"]*');
1265 found_unknown_content($c);
1272 sub handle_loglevel_gif_deanimate ($) {
1274 my $content = shift;
1279 if ($content =~ m/Success! GIF shrunk from (\d+) bytes to (\d+)\./) {
1281 my $bytes_from = $1;
1283 # Gif-Deanimate: Success! GIF shrunk from 205 bytes to 133.
1284 $content =~ s@$bytes_from@$h{'Number'}$bytes_from$h{'Standard'}@;
1285 # XXX: Do we need g in case of ($1 == $2)?
1286 $content =~ s@$bytes_to@$h{'Number'}$bytes_to$h{'Standard'}@;
1288 } elsif ($content =~ m/GIF (not) changed/) {
1290 # Gif-Deanimate: GIF not changed.
1291 return '' if SUPPRESS_GIF_NOT_CHANGED;
1292 $content =~ s@($1)@$h{'not'}$1$h{'Standard'}@;
1294 } elsif ($content =~ m/^failed! \(gif parsing\)/) {
1296 # failed! (gif parsing)
1297 # XXX: Replace this error message with something less stupid
1298 $content =~ s@(failed!)@$h{'error'}$1$h{'Standard'}@;
1300 } elsif ($content =~ m/^Need to de-chunk first/) {
1302 # Need to de-chunk first
1303 return '' if SUPPRESS_NEED_TO_DE_CHUNK_FIRST;
1305 } elsif ($content =~ m/^(?:No GIF header found|failed while parsing)/) {
1307 # No GIF header found (XXX: Did I ever commit this?)
1308 # failed while parsing 195 134747048 (XXX: never commited)
1310 # Ignore these for now
1314 found_unknown_content($content);
1321 sub handle_loglevel_request ($) {
1323 my $content = shift;
1327 our %reason_colours;
1329 if ($content =~ m/crunch! /) {
1331 # config.privoxy.org/send-stylesheet crunch! (CGI Call)
1333 # Highlight crunch reasons
1334 foreach my $reason (keys %reason_colours) {
1335 $content =~ s@\(($reason)\)@$reason_colours{$reason}($1)$h{'Standard'}@g;
1337 # Highlight request URL domain and ditch 'crunch!'
1338 $content = highlight_matched_pattern($content, 'request_', '[^ ]*(?= crunch!)');
1339 $content =~ s@ crunch!@@;
1341 } elsif ($content =~ m/\[too long, truncated\]$/) {
1343 # config.privoxy.org/edit-actions-submit?f=3&v=1176116716&s=7&Submit=Submit[...]&filter... [too long, truncated]
1344 $content = highlight_matched_pattern($content, 'request_', '^.*(?=\.\.\. \[too long, truncated\]$)');
1346 } elsif ($content =~ m/(.*)/) { # XXX: Pretty stupid
1348 # trac.vidalia-project.net/wiki/Volunteer?format=txt
1349 $content = h('request_') . $content . h('Standard');
1353 found_unknown_content($content);
1360 sub handle_loglevel_crunch ($) {
1362 my $content = shift;
1364 our %reason_colours;
1366 # Highlight crunch reason
1367 foreach my $reason (keys %reason_colours) {
1368 $content =~ s@($reason)@$reason_colours{$reason}$1$h{'Standard'}@g;
1371 if ($content =~ m/\[too long, truncated\]$/) {
1373 # Blocked: config.privoxy.org/edit-actions-submit?f=3&v=1176116716&s=7&Submit=Submit\
1374 # [...]&filter... [too long, truncated]
1375 $content = highlight_matched_pattern($content, 'request_', '^.*(?=\.\.\. \[too long, truncated\]$)');
1379 # Blocked: http://ads.example.org/
1380 $content = highlight_matched_pattern($content, 'request_', '(?<=: ).*');
1386 sub handle_loglevel_connect ($) {
1393 if ($c =~ m/^via [^\s]+ to: [^\s]+/) {
1395 # Connect: via 10.0.0.1:8123 to: www.example.org.noconnect
1397 $c = highlight_matched_host($c, '(?<=via )[^\s]+');
1398 $c = highlight_matched_host($c, '(?<=to: )[^\s]+');
1400 } elsif ($c =~ m/^connect to: .* failed: .*/) {
1402 # connect to: www.example.org.noconnect failed: Operation not permitted
1404 $c = highlight_matched_host($c, '(?<=connect to: )[^\s]+');
1406 $c =~ s@(?<=failed: )(.*)@$h{'error'}$1$h{'Standard'}@;
1408 } elsif ($c =~ m/^to ([^\s]*)( successful)?$/) {
1410 # Connect: to www.nzherald.co.nz successful
1411 # Connect: to archiv.radiotux.de
1413 return '' if SUPPRESS_SUCCESSFUL_CONNECTIONS;
1414 $c = highlight_matched_host($c, '(?<=to )[^\s]+');
1416 } elsif ($c =~ m/^to ([^\s]*)$/) {
1418 # Connect: to lists.sourceforge.net:443
1420 $c = highlight_matched_host($c, '(?<=to )[^\s]+');
1422 } elsif ($c =~ m/^accepted connection from .*/ or
1425 # accepted connection from 10.0.0.1
1426 # Privoxy 3.0.6 and earlier just say:
1428 return '' if SUPPRESS_ACCEPTED_CONNECTIONS;
1429 $c = highlight_matched_host($c, '(?<=connection from ).*');
1431 } elsif ($c =~ m/^write header to: .* failed:/) {
1433 # write header to: 10.0.0.1 failed: Broken pipe
1435 $c = highlight_matched_host($c, '(?<=write header to: )[^\s]*');
1436 $c =~ s@(?<=failed: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1438 } elsif ($c =~ m/^write header to client failed:/) {
1440 # write header to client failed: Broken pipe
1442 $c =~ s@(?<=failed: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1444 } elsif ($c =~ m/^socks4_connect:/) {
1446 # socks4_connect: SOCKS request rejected or failed.
1447 $c =~ s@(?<=socks4_connect: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1449 } elsif ($c =~ m/^Listening for new connections/ or
1450 $c =~ m/^accept connection/) {
1452 # Privoxy versions above 3.0.6 say:
1453 # Listening for new connections ...
1454 # earlier versions say:
1455 # accept connection ...
1458 } elsif ($c =~ m/^accept failed:/) {
1460 $c =~ s@(?<=accept failed: )(.*)@$h{'Error'}$1$h{'Standard'}@;
1462 } elsif ($c =~ m/^Overriding forwarding settings/) {
1464 # Overriding forwarding settings based on 'forward 10.0.0.1:8123'
1465 $c =~ s@(?<=based on \')(.*)(?=\')@$h{'configuration-line'}$1$h{'Standard'}@;
1467 } elsif ($c =~ m/^Denying suspicious CONNECT request from/) {
1469 # Denying suspicious CONNECT request from 10.0.0.1
1470 $c = highlight_matched_host($c, '(?<=from )[^\s]+'); # XXX: not an URL
1472 } elsif ($c =~ m/^socks5_connect:/) {
1474 $c =~ s@(?<=socks5_connect: )(.*)@$h{'error'}$1$h{'Standard'}@;
1476 } elsif ($c =~ m/^Created new connection to/) {
1478 # Created new connection to www.privoxy.org:80 on socket 11.
1479 $c = highlight_matched_host($c, '(?<=connection to )[^\s]+');
1480 $c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1482 } elsif ($c =~ m/^Found reusable socket/) {
1484 # Found reusable socket 9 for www.privoxy.org:80 in slot 0.
1486 # Found reusable socket 8 for www.privoxy.org:80 in slot 2.\
1487 # Timestamp made 0 seconds ago. Timeout: 1. Latency: 0.
1488 $c =~ s@(?<=Found reusable socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1489 $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1490 $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1491 $c =~ s@(?<=made )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1492 $c =~ s@(?<=Timeout: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1493 $c =~ s@(?<=Latency: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1495 } elsif ($c =~ m/^Marking open socket/) {
1497 # Marking open socket 9 for www.privoxy.org:80 in slot 0 as unused.
1498 $c =~ s@(?<=Marking open socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1499 $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1500 $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1502 } elsif ($c =~ m/^No reusable/) {
1504 # No reusable socket for addons.mozilla.org:443 found. Opening a new one.
1505 $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1507 } elsif ($c =~ m/^(Remembering|Forgetting) socket/) {
1509 # Remembering socket 13 for www.privoxy.org:80 in slot 0.
1510 # Forgetting socket 38 for www.privoxy.org:80 in slot 5.
1512 $c =~ s@(?<=socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1513 $c = highlight_matched_host($c, '(?<=for )[^\s]+');
1514 $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1516 } elsif ($c =~ m/^Socket/) {
1518 # Socket 16 already forgotten or never remembered.
1519 $c =~ s@(?<=Socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1521 } elsif ($c =~ m/^The connection to/) {
1523 # The connection to www.privoxy.org:80 in slot 6 timed out. Closing socket 19. Timeout is: 61.
1525 # The connection to 1.bp.blogspot.com:80 in slot 0 timed out. Closing socket 5.\
1526 # Timeout is: 1. Assumed latency: 4.
1527 # The connection to 10.0.0.1:80 in slot 0 is no longer usable. Closing socket 4.
1528 $c = highlight_matched_host($c, '(?<=connection to )[^\s]+');
1529 $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1530 $c =~ s@(?<=Closing socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1531 $c =~ s@(?<=Timeout is: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1532 $c =~ s@(?<=Assumed latency: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1534 } elsif ($c =~ m/^Stopped waiting for the request line./) {
1536 # Stopped waiting for the request line. Timeout: 121.
1537 $c =~ s@(?<=Timeout: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1539 } elsif ($c =~ m/^Waiting for \d/) {
1541 # Waiting for 1 connections to timeout.
1542 $c =~ s@(?<=^Waiting for )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1544 } elsif ($c =~ m/^Initialized/) {
1546 # Initialized 20 socket slots.
1547 $c =~ s@(?<=Initialized )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1549 } elsif ($c =~ m/^Done reading from server/) {
1551 # Done reading from server. Expected content length: 24892. \
1552 # Actual content length: 24892. Most recently received: 4412.
1554 # Done reading from server. Expected content length: 24892. \
1555 # Actual content length: 24892. Bytes most recently read: 4412.
1556 # Done reading from server. Content length: 6018 as expected. \
1557 # Bytes most recently read: 294.
1558 $c =~ s@(?<=ontent length: )(\d+)@$h{'Number'}$1$h{'Standard'}@g;
1559 $c =~ s@(?<=received: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1560 $c =~ s@(?<=read: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1562 } elsif ($c =~ m/^Continuing buffering headers/) {
1564 # Continuing buffering headers. byte_count: 19. header_offset: 517. len: 536.
1565 $c =~ s@(?<=byte_count: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1566 $c =~ s@(?<=header_offset: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1567 $c =~ s@(?<=len: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1569 # Continuing buffering headers. Bytes most recently read: %d.
1570 $c =~ s@(?<=read: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1572 } elsif ($c =~ m/^Received \d+ bytes while/) {
1574 # Received 206 bytes while expecting 12103.
1575 $c =~ s@(?<=Received )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1576 $c =~ s@(?<=expecting )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1578 } elsif ($c =~ m/^Connection from/) {
1580 # Connection from 81.163.28.218 dropped due to ACL
1581 $c =~ s@(?<=^Connection from )((?:\d+\.?){4})@$h{'Number'}$1$h{'Standard'}@;
1583 } elsif ($c =~ m/^(?:Reusing|Closing) server socket \d./ or
1584 $c =~ m/^No additional client request/) {
1586 # Reusing server socket 4. Opened for 10.0.0.1.
1587 # Closing server socket 2. Opened for 10.0.0.1.
1588 # No additional client request received in time. \
1589 # Closing server socket 4, initially opened for 10.0.0.1.
1591 $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1592 $c = highlight_matched_host($c, '(?<=for )[^\s]+(?=\.$)');
1594 } elsif ($c =~ m/^Connected to /) {
1596 # Connected to tor-jail[10.0.0.2]:9050.
1598 $c = highlight_matched_host($c, '(?<=\[)[^\]]+');
1599 $c = highlight_matched_host($c, '(?<=Connected to )[^\[\s]+');
1600 $c =~ s@(?<=\]:)(\d+)@$h{'Number'}$1$h{'Standard'}@;
1602 } elsif ($c =~ m/^Could not connect to /) {
1604 # Could not connect to [10.0.0.1]:80.
1606 $c = highlight_matched_host($c, '(?<=\[)[^\]]+');
1607 $c =~ s@(?<=\]:)(\d+)@$h{'Number'}$1$h{'Standard'}@;
1609 } elsif ($c =~ m/^Waiting for the next client request/ or
1610 $c =~ m/^The connection on server socket/ ) {
1612 # Waiting for the next client request. Keeping the server socket 5 to 10.0.0.1 open.
1613 # The connection on server socket 6 to upload.wikimedia.org isn't reusable. Closing.
1615 $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1616 $c = highlight_matched_host($c, '(?<=to )[^\s]+');
1618 } elsif ($c =~ m/^Marking the server socket/) {
1620 # Marking the server socket 7 tainted.
1622 $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1624 } elsif ($c =~ m/^Reduced expected bytes to /) {
1626 # Reduced expected bytes to 0 to account for the 1542 ones we already got.
1627 $c =~ s@(?<=bytes to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1628 $c =~ s@(?<=for the )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1630 } elsif ($c =~ m/^The client closed socket /) {
1632 # The client closed socket 2 while the server socket 4 is still open.
1633 $c =~ s@(?<=closed socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1634 $c =~ s@(?<=server socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1636 } elsif ($c =~ m/^Expected client content length set /) {
1638 # Expected client content length set to 667325411 after reading 4999 bytes.
1639 $c =~ s@(?<=set to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1640 $c =~ s@(?<=reading )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1642 } elsif ($c =~ m/^Waiting for up to /) {
1644 # Waiting for up to 4999 bytes from the client.
1645 $c =~ s@(?<=up to )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1647 } elsif ($c =~ m/^Looks like we rea/ or
1648 $c =~ m/^Unsetting keep-alive flag/ or
1649 $c =~ m/^No connections to wait/ or
1650 $c =~ m/^Client request arrived in time or the client closed the connection/ or
1651 $c =~ m/^Complete client request received/ or
1652 $c =~ m/^Possible pipeline attempt detected./ or
1653 $c =~ m/^POST request detected. The connection will not be kept alive./ or
1654 $c =~ m/^The server still wants to talk, but the client hung up on us./ or
1655 $c =~ m/^The server didn't specify how long the connection will stay open/ or
1656 $c =~ m/^There might be a request body. The connection will not be kept alive/ or
1657 $c =~ m/^Stopping to watch the client socket. There's already another request waiting./ or
1658 $c =~ m/^Done reading from the client\.$/) {
1660 # Looks like we reached the end of the last chunk. We better stop reading.
1661 # Looks like we read the end of the last chunk together with the server \
1662 # headers. We better stop reading.
1663 # Unsetting keep-alive flag.
1664 # No connections to wait for left.
1665 # Client request arrived in time or the client closed the connection.
1666 # Complete client request received
1667 # Possible pipeline attempt detected. The connection will not be \
1668 # kept alive and we will only serve the first request.
1669 # POST request detected. The connection will not be kept alive.
1670 # The server still wants to talk, but the client hung up on us.
1671 # The server didn't specify how long the connection will stay open. Assume it's only a second.
1672 # There might be a request body. The connection will not be kept alive.
1673 # Stopping to watch the client socket. There's already another request waiting.
1674 # Done reading from the client\.
1678 found_unknown_content($c);
1686 sub handle_loglevel_info ($) {
1693 if ($c =~ m/^Rewrite detected:/) {
1695 # Rewrite detected: GET http://10.0.0.2:88/blah.txt HTTP/1.1
1696 $c = highlight_matched_request_line($c, '(?<=^Rewrite detected: ).*');
1698 } elsif ($c =~ m/^Decompress(ing deflated|ion didn)/ or
1699 $c =~ m/^Compressed content detected/ or
1702 # Decompressing deflated iob: 117
1703 # Decompression didn't result in any content.
1704 # Compressed content detected, content filtering disabled. Consider recompiling Privoxy\
1705 # with zlib support or enable the prevent-compression action.
1706 # Tagger 'complete-url' created empty tag. Ignored.
1710 } elsif ($c =~ m/^(Re)?loading configuration file /) {
1712 # loading configuration file '/usr/local/etc/privoxy/config':
1713 # Reloading configuration file '/usr/local/etc/privoxy/config'
1714 $c =~ s@(?<=loading configuration file \')([^\']*)@$h{'file'}$1$h{'Standard'}@;
1716 } elsif ($c =~ m/^exiting by signal/) {
1718 # exiting by signal 15 .. bye
1719 $c =~ s@(?<=exiting by signal )(\d+)@$h{'signal'}$1$h{'Standard'}@;
1721 } elsif ($c =~ m/^Privoxy version/) {
1723 # Privoxy version 3.0.7
1724 $c =~ s@(?<=^Privoxy version )(\d+\.\d+\.\d+)$@$h{'version'}$1$h{'Standard'}@;
1726 } elsif ($c =~ m/^Program name: /) {
1728 # Program name: /usr/local/sbin/privoxy
1729 $c =~ s@(?<=Program name: )(.*)@$h{'program-name'}$1$h{'Standard'}@;
1731 } elsif ($c =~ m/^Listening on port /) {
1733 # Listening on port 8118 on IP address 10.0.0.1
1734 $c =~ s@(?<=Listening on port )(\d+)@$h{'port'}$1$h{'Standard'}@;
1735 $c =~ s@(?<=on IP address )(.*)@$h{'ip-address'}$1$h{'Standard'}@;
1737 } elsif ($c =~ m/^\(Re-\)Open(?:ing)? logfile/) {
1739 # (Re-)Open logfile /var/log/privoxy/privoxy.log
1740 $c =~ s@(?<=Open logfile )(.*)@$h{'file'}$1$h{'Standard'}@;
1742 } elsif ($c =~ m/^(Request from|Malformed server response detected)/) {
1744 # Request from 10.0.0.1 denied. limit-connect{,} doesn't allow CONNECT requests to port 443.
1745 # Request from 10.0.0.1 marked for blocking. limit-connect{,} doesn't allow CONNECT requests to port 443.
1746 # Malformed server response detected. Downgrading to HTTP/1.0 impossible.
1748 $c =~ s@(?<=Request from )([^\s]*)@$h{'ip-address'}$1$h{'Standard'}@;
1749 $c =~ s@(denied|blocking)@$h{'warning'}$1$h{'Standard'}@;
1750 $c =~ s@(CONNECT)@$h{'method'}$1$h{'Standard'}@;
1751 $c =~ s@(?<=to port )(\d+)@$h{'port'}$1$h{'Standard'}@;
1753 } elsif ($c =~ m/^Status code/) {
1755 # Status code 304 implies no body.
1756 $c =~ s@(?<=Status code )(\d+)@$h{'status-code'}$1$h{'Standard'}@;
1758 } elsif ($c =~ m/^Method/) {
1760 # Method HEAD implies no body.
1761 $c =~ s@(?<=Method )([^\s]+)@$h{'method'}$1$h{'Standard'}@;
1763 } elsif ($c =~ m/^Buffer limit reached while extending /) {
1765 # Buffer limit reached while extending the buffer (iob). Needed: 4197470. Limit: 4194304
1766 $c =~ s@(?<=Needed: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1767 $c =~ s@(?<=Limit: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1769 } elsif ($c =~ m/^No logfile configured/ or
1770 $c =~ m/^Malformerd HTTP headers detected and MS IIS5 hack enabled/ or
1771 $c =~ m/^Invalid \"chunked\" transfer/ or
1772 $c =~ m/^Support for/ or
1773 $c =~ m/^Flushing header and buffers/
1776 # No logfile configured. Please enable it before reporting any problems.
1777 # Malformerd HTTP headers detected and MS IIS5 hack enabled. Expect an invalid \
1778 # response or even no response at all.
1779 # No logfile configured. Logging disabled.
1780 # Invalid "chunked" transfer encoding detected and ignored.
1781 # Support for 'Connection: keep-alive' is experimental, incomplete and\
1782 # known not to work properly in some situations.
1783 # Flushing header and buffers. Stepping back from filtering.
1787 found_unknown_content($c);
1794 sub handle_loglevel_cgi ($) {
1801 if ($c =~ m/^Granting access to/) {
1803 #Granting access to http://config.privoxy.org/send-stylesheet, referrer http://p.p/ is trustworthy.
1805 } elsif ($c =~ m/^Substituting: s(.)/) {
1807 # Substituting: s/@else-not-FEATURE_ZLIB@.*@endif-FEATURE_ZLIB@//sigTU
1808 # XXX: prone to span several lines
1811 #$c =~ s@(?<=failed: )(.*)@$h{'error'}$1$h{'Standard'}@;
1812 $c =~ s@(?!<=\\)($delimiter)@$h{'pcrs-delimiter'}$1$h{'Standard'}@g; # XXX: Too aggressive
1813 #$c =~ s@(?!<=\\)($1)@$h{'pcrs-delimiter'}$1$h{'Standard'}@g;
1819 sub handle_loglevel_force ($) {
1826 if ($c =~ m/^Ignored force prefix in request:/) {
1828 # Ignored force prefix in request: "GET http://10.0.0.1/PRIVOXY-FORCE/block HTTP/1.1"
1829 $c =~ s@^(Ignored)@$h{'ignored'}$1$h{'Standard'}@;
1830 $c = highlight_matched_request_line($c, '(?<=request: ")[^"]*');
1832 } elsif ($c =~ m/^Enforcing request:/) {
1834 # Enforcing request: "GET http://10.0.0.1/block HTTP/1.1".
1835 $c = highlight_matched_request_line($c, '(?<=request: ")[^"]*');
1839 found_unknown_content($c);
1846 sub handle_loglevel_error ($) {
1851 if ($c =~ m/^Empty server or forwarder response received on socket \d+./) {
1853 # Empty server or forwarder response received on socket 4.
1854 $c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
1856 # XXX: There are probably more messages that deserve highlighting.
1862 sub handle_loglevel_ignore ($) {
1866 sub gather_loglevel_request_stats ($$) {
1874 sub gather_loglevel_crunch_stats ($$) {
1884 sub gather_loglevel_error_stats ($$) {
1891 if ($c =~ m/^Empty server or forwarder response received on socket \d+./) {
1893 # Empty server or forwarder response received on socket 4.
1894 $stats{'empty-responses'}++;
1895 if ($thread_data{$thread}{'new_connection'}) {
1896 $stats{'empty-responses-on-new-connections'}++;
1898 $stats{'empty-responses-on-reused-connections'}++;
1903 sub gather_loglevel_connect_stats ($$) {
1910 if ($c =~ m/^via ([^\s]+) to: [^\s]+/) {
1912 # Connect: via 10.0.0.1:8123 to: www.example.org.noconnect
1913 $thread_data{$thread}{'forwarder'} = $1; # XXX: is this missue?
1915 } elsif ($c =~ m/^to ([^\s]*)$/) {
1917 # Connect: to lists.sourceforge.net:443
1919 $thread_data{$thread}{'forwarder'} = 'direct connection';
1921 } elsif ($c =~ m/^Created new connection to/) {
1923 # Created new connection to www.privoxy.org:80 on socket 11.
1925 $thread_data{$thread}{'new_connection'} = 1;
1927 } elsif ($c =~ m/^Reusing server socket \d./ or
1928 $c =~ m/^Found reusable socket/) {
1930 # Reusing server socket 4. Opened for 10.0.0.1.
1931 # Found reusable socket 9 for www.privoxy.org:80 in slot 0.
1933 $thread_data{$thread}{'new_connection'} = 0;
1934 $stats{'reused-connections'}++;
1938 sub gather_loglevel_header_stats ($) {
1944 if ($c =~ m/^A HTTP\/1\.1 response without/ or
1945 $c =~ m/^Keeping the server header 'Connection: keep-alive' around./)
1947 # A HTTP/1.1 response without Connection header implies keep-alive.
1948 # Keeping the server header 'Connection: keep-alive' around.
1949 $stats{'server-keep-alive'}++;
1957 'server-keep-alive' => 0,
1958 'reused-connections' => 0,
1959 'empty-responses' => 0,
1960 'empty-responses-on-new-connections' => 0,
1961 'empty-responses-on-reused-connections' => 0,
1965 sub get_percentage ($$) {
1968 return "NaN" if ($big eq 0);
1969 return sprintf("%.2f%%", $small / $big * 100);
1972 sub print_stats () {
1975 my $new_connections = $stats{requests} - $stats{crunches} - $stats{'reused-connections'};
1976 my $outgoing_requests = $stats{requests} - $stats{crunches};
1978 if ($stats{requests} eq 0) {
1979 print "No requests yet.\n";
1983 print "Client requests total: " . $stats{requests} . "\n";
1984 print "Crunches: " . $stats{crunches} . " (" .
1985 get_percentage($stats{requests}, $stats{crunches}) . ")\n";
1986 print "Outgoing requests: " . $outgoing_requests . " (" .
1987 get_percentage($stats{requests}, $outgoing_requests) . ")\n";
1988 print "Server keep-alive offers: " . $stats{'server-keep-alive'} . " (" .
1989 get_percentage($stats{requests}, $stats{'server-keep-alive'}) . ")\n";
1990 print "New outgoing connections: " . $new_connections . " (" .
1991 get_percentage($stats{requests}, $new_connections) . ")\n";
1992 print "Reused connections: " . $stats{'reused-connections'} . " (" .
1993 get_percentage($stats{requests}, $stats{'reused-connections'}) . ")\n";
1994 print "Empty responses: " . $stats{'empty-responses'} . " (" .
1995 get_percentage($stats{requests}, $stats{'empty-responses'}) . ")\n";
1996 print "Empty responses on new connections: "
1997 . $stats{'empty-responses-on-new-connections'} . " (" .
1998 get_percentage($stats{requests}, $stats{'empty-responses-on-new-connections'})
2000 print "Empty responses on reused connections: " .
2001 $stats{'empty-responses-on-reused-connections'} . " (" .
2002 get_percentage($stats{requests}, $stats{'empty-responses-on-reused-connections'}) .
2007 ################################################################################
2008 # Functions that actually print stuff
2009 ################################################################################
2011 sub print_clf_message () {
2013 our ($ip, $timestamp, $request_line, $status_code, $size);
2017 return if DEBUG_SUPPRESS_LOG_MESSAGES;
2019 # Rebuild highlighted
2020 $output .= $h{'Number'} . $ip . $h{'Standard'};
2022 $output .= "[" . $h{'Timestamp'} . $timestamp . $h{'Standard'} . "]";
2024 $output .= "\"" . highlight_request_line("$request_line") . "\"";
2026 $output .= $h{'Status'} . $status_code . $h{'Standard'};
2028 $output .= $h{'Number'} . $size . $h{'Standard'};
2029 $output .= get_line_end();
2034 sub print_non_clf_message ($) {
2037 our %thread_colours;
2040 our $time_colour_index;
2043 my $content = shift;
2044 my ($day, $time_stamp, $msecs, $thread, $log_level)
2045 = ($req{$t}{'day'}, $req{$t}{'time-stamp'}, $req{$t}{'msecs'}, $t, $req{$t}{'log-level'} );
2047 return if DEBUG_SUPPRESS_LOG_MESSAGES;
2049 $output .= $h{"Standard"} unless cli_option_is_set('html-output');
2050 # $output .= "$day ";
2051 $output .= $time_colours[$time_colour_index % 2];
2053 $output .= $time_stamp;
2054 $output .= ".$msecs" unless cli_option_is_set('no-msecs');
2055 $output .= $h{"Standard"};
2057 $output .= $thread_colours{$thread} if (defined($thread_colours{$thread}));
2059 $output .= $h{"Standard"} . " ";
2060 $output .= $h{$log_level} if (defined($h{$log_level}));
2061 $output .= $log_level;
2062 $output .= $h{"Standard"} . ": ";
2063 $output .= "$content";
2064 $output .= get_line_end();
2072 our %req; # request data from previous lines
2074 our %thread_colours;
2077 our $thread_colour_index = 0;
2078 our $header_colour_index = 0;
2079 our $time_colour_index = 0;
2081 my ($day, $time_stamp, $thread, $log_level, $content, $c, $msecs);
2083 my $last_thread = 0;
2084 my $last_timestamp = 0;
2086 my $filters_that_did_nothing;
2089 our $no_special_header_highlighting;
2090 $time_colour = paint_it('white');
2092 my %log_level_handlers = (
2093 'Re-Filter' => \&handle_loglevel_re_filter,
2094 'Header' => \&handle_loglevel_header,
2095 'Connect' => \&handle_loglevel_connect,
2096 'Redirect' => \&handle_loglevel_redirect,
2097 'Request' => \&handle_loglevel_request,
2098 'Crunch' => \&handle_loglevel_crunch,
2099 'Gif-Deanimate' => \&handle_loglevel_gif_deanimate,
2100 'Info' => \&handle_loglevel_info,
2101 'CGI' => \&handle_loglevel_cgi,
2102 'Force' => \&handle_loglevel_force,
2103 'Error' => \&handle_loglevel_error,
2104 'Fatal error' => \&handle_loglevel_ignore,
2105 'Writing' => \&handle_loglevel_ignore,
2106 'Unknown log level' => \&handle_loglevel_ignore,
2113 if (m/^(\w{3} \d{2}) (\d\d:\d\d:\d\d)\.?(\d+)? (?:Privoxy\()?([^\)\s]*)[\)]? ([\w -]*): (.*?)\r?$/) {
2114 # XXX: Put in req hash?
2117 $msecs = $3 ? $3 : 0; # Only the cool kids have micro second resolution
2122 $req{$t}{'day'} = $day;
2123 $req{$t}{'time-stamp'} = $time_stamp;
2124 $req{$t}{'msecs'} = $msecs; # Only the cool kids have micro second resolution;
2125 $req{$t}{'log-level'} = $log_level;
2126 $req{$t}{'content'} = $content;
2127 $req{$t}{'log-message'} = $_;
2128 $no_special_header_highlighting = 0;
2130 if (defined($log_level_handlers{$log_level})) {
2132 $content = $log_level_handlers{$log_level}($content);
2136 die "No handler found for log level \"$log_level\"\n";
2140 # Highlight Truncations
2141 if (m/\.\.\. \[(too long, truncated)/) {
2142 $content =~ s@($1)@$h{'Truncation'}$1$h{'Standard'}@g;
2145 next unless $content;
2147 # Register threads to keep the colour constant
2148 if (!defined($thread_colours{$thread})) {
2149 $thread_colours{$thread} = $all_colours[$thread_colour_index % @all_colours];
2150 $thread_colour_index++;
2153 # Switch timestamp colour if timestamps differ
2154 if ($msecs != $last_msecs || !($time_stamp =~ m/$last_timestamp/)) {
2155 debug_message("Tick tack!") if DEBUG_TICKS;
2156 $time_colour = $time_colours[$time_colour_index % 2];
2157 $time_colour_index++
2160 $last_msecs = $msecs;
2161 $last_thread = $thread;
2162 $last_timestamp = $time_stamp;
2164 print_non_clf_message($content);
2166 } elsif (m/^((?:\d+\.\d+\.\d+\.\d+|[:\d]+)) - - \[(.*)\] "(.*)" (\d+) (\d+)/) {
2168 # LOG_LEVEL_CLF lines look like this
2169 # 61.152.239.32 - - [04/Mar/2007:18:28:23 +0100] "GET \
2170 # http://ad.yieldmanager.com/imp?z=1&Z=120x600&s=109339&u=http%3A%2F%2Fwww.365loan.co.uk%2F&r=1\
2171 # HTTP/1.1" 403 1730
2172 our ($ip, $timestamp, $request_line, $status_code, $size) = ($1, $2, $3, $4, $5);
2174 print_clf_message();
2178 # Some Privoxy log messages span more than one line,
2179 # usually to dump lots of content that doesn't need any syntax highlighting.
2180 # XXX: add mechanism to forward these lines to the right handler anyway.
2182 unless (DEBUG_SUPPRESS_LOG_MESSAGES or (SUPPRESS_EMPTY_LINES and m/^\s+$/)) {
2183 print and print get_line_end(); # unless (SUPPRESS_EMPTY_LINES and m/^\s+$/);
2191 my ($day, $time_stamp, $thread, $log_level, $content, $c, $msecs);
2192 my %log_level_handlers = (
2193 'Re-Filter' => \&handle_loglevel_ignore,
2194 'Header' => \&gather_loglevel_header_stats,
2195 'Connect' => \&gather_loglevel_connect_stats,
2196 'Redirect' => \&handle_loglevel_ignore,
2197 'Request' => \&gather_loglevel_request_stats,
2198 'Crunch' => \&gather_loglevel_crunch_stats,
2199 'Gif-Deanimate' => \&handle_loglevel_ignore,
2200 'Info' => \&handle_loglevel_ignore,
2201 'CGI' => \&handle_loglevel_ignore,
2202 'Force' => \&handle_loglevel_ignore,
2203 'Error' => \&gather_loglevel_error_stats,
2204 'Fatal error' => \&handle_loglevel_ignore,
2205 'Writing' => \&handle_loglevel_ignore,
2206 'Unknown log level' => \&handle_loglevel_ignore
2210 if (m/^(\w{3} \d{2}) (\d\d:\d\d:\d\d)\.?(\d+)? (?:Privoxy\()?([^\)\s]*)[\)]? ([\w -]*): (.*?)\r?$/) {
2213 $msecs = $3 ? $3 : 0;
2218 if (defined($log_level_handlers{$log_level})) {
2220 $content = $log_level_handlers{$log_level}($content, $thread);
2224 die "No handler found for log level \"$log_level\"\n";
2234 sub VersionMessage {
2235 my $version_message;
2237 $version_message .= 'Privoxy-Log-Parser ' . PRIVOXY_LOG_PARSER_VERSION . "\n";
2238 $version_message .= 'Copyright (C) 2007-2009 Fabian Keil <fk@fabiankeil.de>' . "\n";
2239 $version_message .= 'http://www.fabiankeil.de/sourcecode/privoxy-log-parser/' . "\n";
2241 print $version_message;
2244 sub get_cli_options () {
2246 our %cli_options = (
2247 'html-output' => CLI_OPTION_DEFAULT_TO_HTML_OUTPUT,
2248 'title' => CLI_OPTION_TITLE,
2249 'no-syntax-highlighting' => CLI_OPTION_NO_SYNTAX_HIGHLIGHTING,
2250 'no-embedded-css' => CLI_OPTION_NO_EMBEDDED_CSS,
2251 'no-msecs' => CLI_OPTION_NO_MSECS,
2252 'show-ineffective-filters' => CLI_OPTION_SHOW_INEFFECTIVE_FILTERS,
2253 'accept-unknown-messages' => CLI_OPTION_ACCEPT_UNKNOWN_MESSAGES,
2254 'statistics' => CLI_OPTION_STATISTICS,
2258 'html-output' => \$cli_options{'html-output'},
2259 'title' => \$cli_options{'title'},
2260 'no-syntax-highlighting' => \$cli_options{'no-syntax-highlighting'},
2261 'no-embedded-css' => \$cli_options{'no-embedded-css'},
2262 'no-msecs' => \$cli_options{'no-msecs'},
2263 'show-ineffective-filters' => \$cli_options{'show-ineffective-filters'},
2264 'accept-unknown-messages' => \$cli_options{'accept-unknown-messages'},
2265 'statistics' => \$cli_options{'statistics'},
2266 'version' => sub { VersionMessage && exit(0) },
2279 Options and their default values if they have any:
2280 [--accept-unknown-messages]
2284 [--no-syntax-highlighting]
2285 [--show-ineffective-filters]
2287 [--title $cli_options{'title'}]
2289 see "perldoc $0" for more information
2295 ################################################################################
2297 ################################################################################
2301 set_background(DEFAULT_BACKGROUND);
2302 prepare_our_stuff();
2306 if (cli_option_is_set('statistics')) {
2319 B<privoxy-log-parser> - A parser and syntax-highlighter for Privoxy log messages
2323 B<privoxy-log-parser> [B<--accept-unknown-messages>] [B<--html-output>]
2324 [B<--no-msecs>] [B<--no-syntax-higlighting>] [B<--show-ineffective-filters>]
2329 B<privoxy-log-parser> reads Privoxy log messages and
2331 - syntax-highlights recognized lines,
2333 - reformats some of them for easier comprehension,
2335 - filters out less useful messages, and
2337 - (in some cases) calculates additional information,
2338 like the compression ratio or how a filter affected
2341 With B<privoxy-log-parser> you should be able to increase Privoxy's log level
2342 without getting confused by the resulting amount of output. For example for
2343 "debug 64" B<privoxy-log-parser> will (by default) only show messages that
2344 affect the content. If a filter doesn't cause any hits, B<privoxy-log-parser>
2345 will hide the "filter foo caused 0 hits" message.
2349 [B<--accept-unknown-messages>] Don't print warnings in case of unknown messages,
2350 just don't highlight them.
2352 [B<--html-output>] Use HTML and CSS for the syntax highlighting. If this option is
2353 omitted, ANSI escape sequences are used unless B<--no-syntax-highlighting> is active.
2354 This option is only intended to make embedding log excerpts in web pages easier.
2355 It does not escape any input!
2357 [B<--no-msecs>] Don't expect milisecond resolution
2359 [B<--no-syntax-highlighting>] Disable syntax-highlighting. Useful when
2360 the filtered output is piped into less in which case the ANSI control
2361 codes don't work, or if the terminal itself doesn't support the control
2364 [B<--show-ineffective-filters>] Don't suppress log lines for filters
2365 that didn't modify the content.
2367 [B<--statistics>] Gather various statistics instead of syntax highlighting
2368 log messages. This is an experimental feature, if the results look wrong
2369 they very well might be. Also note that the results a pretty much guaranteed
2370 to be incorrect if Privoxy and Privoxy-Log-Parser aren't in sync.
2372 [B<--version>] Print version and exit.
2376 To monitor a log file:
2378 tail -F /usr/jails/privoxy-jail/var/log/privoxy/privoxy.log | B<privoxy-log-parser>
2380 Replace '-F' with '-f' if your tail implementation lacks '-F' support
2381 or if the log won't get rotated anyway. The log file location depends
2382 on your system (Doh!).
2384 To monitor Privoxy without having it write to a log file:
2386 privoxy --no-daemon /usr/jails/privoxy-jail/usr/local/etc/privoxy/config 2>&1 | B<privoxy-log-parser>
2388 Again, the config file location depends on your system. Output redirection
2389 depends on your shell, the above works with bourne shells.
2391 To read a processed Privoxy log file from top to bottom, letting the content
2392 scroll by slightly faster than you can read:
2394 B<privoxy-log-parser> < /usr/jails/privoxy-jail/var/log/privoxy/privoxy.log
2396 This is probably only useful to fill screens in the background of haxor movies.
2400 Syntax highlighting with ANSI escape sequences will look strange
2401 if your background color isn't black.
2403 Some messages aren't recognized yet and will not be fully highlighted.
2405 B<privoxy-log-parser> is developed with Privoxy 3.0.7 or later in mind,
2406 using earlier Privoxy versions will probably result in an increased amount
2407 of unrecognized log lines.
2409 Privoxy's log files tend to be rather large. If you use HTML
2410 highlighting some browsers can't handle them, get confused and
2411 will eventually crash because of segmentation faults or unexpected
2412 exceptions. This is a problem in the browser and not B<privoxy-log-parser>'s
2417 Many settings can't be controlled through command line options yet.
2425 Fabian Keil <fk@fabiankeil.de>