Blog2014 ≫ Multi colour access logs

I'm tailing my access logs, as I'm dull like that. I want to see waht's coming in live but I want to highlight different kinds of requests. So I started colour coding them, and now I'm extending it a bit further... assuming your access logs are at /var/log/httpd/access_log try pasting this into the console (bet this doesn't come out):

RESET=`echo -en '\e[00m'`
GREY=`echo -en '\e[37m'`
DARKGREEN=`echo -en '\e[93m'`
LIGHTGREEN=`echo -en '\e[32m'`
tail -f /var/log/httpd/access_log | sed -E "s/\[.*\] //; s/^/         /; s/ (.*\" 200 .*)/ $LIGHTGREEN\1/g; s/ (.*\" 301 .*)/ $DARKGREEN\1/g; s/        (.*(bot|crawl).*)/$GREY\\d\[o_0\]b \1/; s/\$/$RESET/"

I'm now prowling 1lineart.kulaone.com1 for one line ascii art (that's what I'm using to show the little robot face

d[o_0]b

when the access log line is from a bot / crawler (like google etc). The other code colours the line grey if it is from a crawler, bright green if it is a new successful hit on the site and a darker green if it is a hit on the site served up from the cache.

More to follow.

⬅️ :: ➡️

Paul Clarke's weblog - I live in Hythe near Folkestone. Wed to Clare + dad to 2, I am a full stack web engineer, + I do js / Node, some ruby, python, php etc. I like pubs, parkrun, eating, home-automation + other diy jiggery-pokery, history, genealogy, TV, squirrels, pirates, lego, + TIME TRAVEL.