#!/usr/bin/perl -w
#
#  pflogcolor -- colorize Postfix logs for easy reading
#
#  $Id: pflogcolor,v 1.1 2004/06/25 15:26:29 root Exp root $

use strict;
use Term::ANSIColor;

my %base_colors = (
    'smtp postfix' => 'white on_blue',
    'smtp amavis' => 'yellow',
    'smtp update-datfile' => 'blue',
    'last message repeated' => 'bold blue',
);

my %colors = (
    'smtp postfix/(?!lmtp).*status=deferred'         => 'bold yellow on_blue',
    'smtp postfix/(?!lmtp).*status=sent'             => 'bold green on_blue',
    'smtp postfix/(?!lmtp).*status=bounced'          => 'bold red on_blue',
    'smtp postfix/(?!lmtp).*reject'                  => 'bold red on_blue',
    'smtp amavis.*SPAM,'		   => 'bold magenta on_yellow',
    'smtp amavis.*INFECT'                  => 'bold red on_yellow',
    'smtp.*fatal'			   => 'bold white on_red',
    'smtp.*warn'                           => 'black on_yellow',
);

$|++;

while (<>)
{
    chomp;
    my $color = undef;
 
    for my $c (keys %base_colors)
    {
        $color = $base_colors{$c} if /$c/;
    }

    for my $c (keys %colors)
    {
        $color = $colors{$c} if /$c/;
    }
   
    print color "$color" if defined $color;
    print;
    print color "reset" if defined $color;
    print "\n";
}

