Skip to content

Instantly share code, notes, and snippets.

@simonjgreen
Last active December 21, 2015 18:28
Show Gist options
  • Save simonjgreen/6347157 to your computer and use it in GitHub Desktop.
Save simonjgreen/6347157 to your computer and use it in GitHub Desktop.
Colourises an access log
#Puts a splash of colour in your access logs. IP addresses are gray, 200 and 304 are green, all 4xx errors are red.
#Works well with e.g. "colourise access_log | less -R" if you want to see your colours while paging.
#Use as inspiration for other things you might be tailing, like syslog or vmstat
#Usage:
#tail -f access.log | colourise
function colourise() { c="--line-buffered --color=yes"; GREP_COLORS="mt=01;34" egrep $c '(^| 200 | 304 )' "${@}" | GREP_COLORS="mt=02;31" egrep $c '(^|"(GET|POST) .*[^0-9] 4[0-1][0-9] )' | GREP_COLORS="ms=02;37" egrep $c '(^|^[0-9\.]+) ';}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment