User Tools

Site Tools


apachelogcolor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
apachelogcolor [2006/11/13 12:20] 205.252.23.12apachelogcolor [2006/11/13 13:32] (current) – old revision restored andi
Line 1: Line 1:
 +====== Apache logfile colorizer ======
 +
 +This simple script reads loglines in Apaches "combined" format from STDIN, and prints relevant data nicely colored to the terminal. This script is very nice to watch whats going on on your website.
 +
 +<code perl>
 +#!/usr/bin/perl
 +
 +$black="\033[30m";
 +$red="\033[31m";
 +$green="\033[32m";
 +$yellow="\033[33m";
 +$blue="\033[34m";
 +$magenta="\033[35m";
 +$cyan="\033[36m";
 +$white="\033[37m";
 +
 +while(<STDIN>){
 + m/(\S+?) (\S+?) (\S+?) \[(.+?)\] "\S+? (\S+?) HTTP\S+?" (\d*?) (\d*?) "(.*?)" "(.*?)"/;
 +
 + print $red;
 + print "$1 ";     # IP
 + print $green;
 + print "$6 ";     # Status
 + print $yellow;
 + print "$5 ";     # Request
 + print $cyan;
 + print "$8 ";     # Referrer
 + print $magenta;
 + print "$9 ";     # Browser
 + print $white;
 + print "\n";
 +}
 +</code>
 +
 +Example Usage:
 +
 +  $> tail -f /var/log/apache/access.log | ./livelog.pl
 +
  
apachelogcolor.txt · Last modified: 2006/11/13 13:32 by andi