Skip to content

Instantly share code, notes, and snippets.

@fquinto
Forked from liufuyang/tailc
Last active October 25, 2021 18:48
Show Gist options
  • Save fquinto/4bb8059d96f4135de2c4e60ee21c5f3c to your computer and use it in GitHub Desktop.
Save fquinto/4bb8059d96f4135de2c4e60ee21c5f3c to your computer and use it in GitHub Desktop.
Color output of linux tail command
#!/bin/bash
# Laravel PHP coloring logger
# save this file as tailc then
# run as: $ tailc logs/supplier-matching-worker.log Words_to_highlight
file=$1
if [[ -n "$2" ]]; then
color='
// {print "\033[37m" $0 "\033[39m"}
/('$2')/ {print "\033[1;31m" $0 "\033[0m"}
'
else
color='
// { }
/(.EMERGENCY)/ {print "\033[1;45m" $0 "\033[0m"}
/(.ALERT)/ {print "\033[1;35m" $0 "\033[0m"}
/(.CRITICAL)/ {print "\033[1;43m" $0 "\033[0m"}
/(.ERROR)/ {print "\033[1;31m" $0 "\033[0m"}
/(.WARN|WARNING)/ {print "\033[1;33m" $0 "\033[0m"}
/(.NOTICE)/ {print "\033[1;32m" $0 "\033[0m"}
/(.INFO)/ {print "\033[1;34m" $0 "\033[0m"}
/(.DEBUG)/ {print "\033[1;37m" $0 "\033[0m"}
'
fi
tail -5000f $file | awk "$color"
# Colors
# 30 - black 34 - blue 40 - black 44 - blue
# 31 - red 35 - magenta 41 - red 45 - magenta
# 32 - green 36 - cyan 42 - green 46 - cyan
# 33 - yellow 37 - white 43 - yellow 47 - white
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment