[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Jul 2004
]
Re: [edlug] Watching the Logs
Peter George wrote:
I want to 'watch' my httpd logs accrue new entries in real-time.
What command should I issue to do this?
tail -f log.file | logcolorize.pl
logcolorize.pl:
---cut here---
#!/usr/bin/perl
# logcolorize.pl - A PERL script to colorize log viewing
# Version 1.0.1
# License: GPL version 2 or later
# Copyright: (C) 1999, Michael T. Babcock
# <mikebabcock@xxx.xxx.xxx>
# http://www.linuxsupportline.com/~pgp/linux/
# Special Thanks
# colorlogs.pl -- I ripped the colors and this header for this script.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
######################################################################
# Create the colors Assoc. Array
%colors = (
'black' => "\033[30m",
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m",
'blue' => "\033[34m",
'magenta' => "\033[35m",
'purple' => "\033[35m",
'cyan' => "\033[36m",
'white' => "\033[37m",
'darkgray' => "\033[30m");
# Now define what we want to use when:
$col_good = "green";
$col_warn = "yellow";
$col_bad = "red";
$col_note = "purple";
$col_norm = "\033[00m";
$col_background = "\033[07m";
$col_brighten = "\033[01m";
$col_underline = "\033[04m";
$col_blink = "\033[05m";
$col_default = "$col_norm$colors{white}";
print "\n$col_norm$colors{cyan}logcolorize.pl 1.0.2 by
$col_brighten$colors{cyan}Michael T. Babcock$col_norm$colors{cyan}
<$col_brighten$colors{green}mikebabcock\@pobox.com$col_norm$colors{cyan}>\n";
$datespace=0;
while (<>)
{
$thisline = $_;
@rec = split (/ /, $thisline);
$output ="$col_brighten$colors{'cyan'}";
$output.="$rec[0] ";
if ($rec[1] eq "")
{
$datespace=1;
}
$output.="$rec[1+$datespace] $rec[2+$datespace] ";
$output.="$col_brighten$colors{'blue'}$rec[3+$datespace] ";
@service=split(/\[/,$rec[(4+$datespace)]);
@service2=split(/]/,$service[1]);
$output.="$col_norm$colors{'green'}$service[0]$col_brighten$colors{'green'}\[";
$output.="$col_brighten$colors{'white'}$service2[0]$col_brighten$colors{'green'}\]:
";
$restcolor="$col_norm$colors{'cyan'}";
$restoftheline="";
for ($therest=(5+$datespace); $therest<=$#rec; $therest++)
{
$highlight=0;
# Here we check for keywords to highlight ...
if ($rec[$therest] eq "starting\n" ||
$rec[$therest] eq "starting." ||
$rec[$therest] eq "Ready" ||
$rec[$therest] eq "active" ||
$rec[$therest] eq "reloading" ||
$rec[$therest] eq "saved;" ||
$rec[$therest] eq "restarting")
{
$restoftheline.="$col_brighten$colors{$col_good}";
$highlight=1;
}
if ($rec[$therest] eq "dangling" ||
$rec[$therest] eq "Assuming" ||
$rec[$therest] eq "root" ||
$rec[$therest] eq "root\n" ||
$rec[$therest] eq "missing" ||
$rec[$therest] eq "Ignored" ||
$rec[$therest] eq "adminalert:" ||
$rec[$therest] eq "deleting")
{
$restoftheline.="$col_brighten$colors{$col_warn}";
$highlight=1;
}
# Here we watch for words that indicate entire lines should be highlighted
if ($rec[$therest] eq "invalid" ||
$rec[$therest] eq "bad" ||
$rec[$therest] eq "attackalert:" ||
$rec[$therest] eq "wrong" ||
$rec[$therest] eq "Lame" ||
$rec[$therest] eq "failing" ||
$rec[$therest] eq "unknown" ||
$rec[$therest] eq "denied" ||
$rec[$therest] eq "obsolete")
{
$restcolor="$col_norm$colors{$col_warn}";
$restoftheline.="$col_brighten$colors{$col_warn}";
$highlight=1;
}
if ($rec[$therest] eq "LOGIN" ||
$rec[$therest] eq "DHCP_OFFER" ||
$rec[$therest] eq "connect" ||
$rec[$therest] eq "Successful")
{
$restoftheline.="$col_brighten$colors{$col_note}";
$highlight=1;
}
if ($rec[$therest] eq "up" ||
$rec[$therest] eq "DHCP_ACK" ||
$rec[$therest] eq "Cleaned" ||
$rec[$therest] eq "alive" ||
$rec[$therest] eq "found")
{
$restcolor="$col_norm$colors{$col_good}";
$restoftheline.="$col_brighten$colors{$col_good}";
$highlight=1;
}
if ($rec[$therest] eq "DENY" ||
$rec[$therest] eq "lost" ||
$rec[$therest] eq "shutting" ||
$rec[$therest] eq "dead" ||
$rec[$therest] eq "DHCP_NAK" ||
$rec[$therest] eq "failure;" ||
$rec[$therest] eq "inactive" ||
$rec[$therest] eq "terminating" ||
$rec[$therest] eq "refused" ||
$rec[$therest] eq "rejected" ||
$rec[$therest] eq "down")
{
$restcolor="$col_norm$colors{$col_bad}";
$restoftheline.="$col_brighten$colors{$col_bad}";
$highlight=1;
}
$restoftheline.="$rec[$therest] ";
if ($highlight == 1)
{
$restoftheline.=$restcolor;
}
}
$output.="$restcolor$restoftheline";
print $output;
print $col_default;
}
print $col_default;
---cut here---
--
George Barnett
Reality Engineer & Explorer
e: george@xxx.xxx.xxx
m: +44 778 884 7205
Things must be as they may
- William Shakespear, Henry V
-
----------------------------------------------------------------------
You can find the EdLUG mailing list FAQ list at:
http://www.edlug.org.uk/list_faq.html