Last active
December 21, 2015 18:28
-
-
Save simonjgreen/6347157 to your computer and use it in GitHub Desktop.
Colourises an access log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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