Skip to content

Instantly share code, notes, and snippets.

@Clijsters
Last active January 6, 2023 13:01
Show Gist options
  • Save Clijsters/18133241d113b2e3ba49a4d066fa46d6 to your computer and use it in GitHub Desktop.
Save Clijsters/18133241d113b2e3ba49a4d066fa46d6 to your computer and use it in GitHub Desktop.
tail color output

multiWatch.sh

An awk snippet for color highlighting Apache Logs pumped to the pipe with tail -f. Based on some basic awk RegEx and bash color codes. Keep in mind that this is generally really basic stuff and more than 10 years old. We don't do things like that anymore.

Example output

Screenshot

What's next

I want to make it more flexibel with json configuration. I'm thinking about an implementation with npm Tail, jVectorMap and some HTML websockets - An event based architecture which triggers a web app, console output, mail notifications and so on.

tail -f /var/www/vhosts/*/logs/* | awk '
/(HTTP)\/1.1..(404|304)([0-9]+)?/ {printf "\033[93m" $1" "$4"] " $6 " " $7 " " $8 " \033[41m" $9 "\033[40m "; for(i=11;i<NF;i++){printf " %s", $i}; print "\033[39m";next}
/(HTTP)\/1.1..(4|5)([0-9]+)?/ {print "\033[31m" $0 "\033[39m";next}
/(HTTP)\/1.1..(2|3)([0-9]+)?/ {print "\033[92m" $0 "\033[39m";next}
/(warn|error)/ {print "\033[31m" $0 "\033[39m";next}
1
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment