Skip to content

Instantly share code, notes, and snippets.

@achristodoulou
Last active June 25, 2018 11:05
Show Gist options
  • Save achristodoulou/24f100811debd36c15cc to your computer and use it in GitHub Desktop.
Save achristodoulou/24f100811debd36c15cc to your computer and use it in GitHub Desktop.
Tail logs with color for Monolog
#1. Copy/paste the below lines in your .bashrc
tailf-with-colors () {
if [ -z "$1" ] ; then
echo "Please specify a file for monitoring"
return
fi
tail -f $1 | awk '
{matched=0}
/INFO:/ {matched=1; print "\033[0;37m" $0 "\033[0m"} # WHITE
/NOTICE:/ {matched=1; print "\033[0;36m" $0 "\033[0m"} # CYAN
/WARNING:/ {matched=1; print "\033[0;34m" $0 "\033[0m"} # BLUE
/ERROR:/ {matched=1; print "\033[0;31m" $0 "\033[0m"} # RED
/ALERT:/ {matched=1; print "\033[0;35m" $0 "\033[0m"} # PURPLE
matched==0 {print "\033[0;33m" $0 "\033[0m"} # YELLOW
'
}
#2. Run source ~/.bashrc -- to reload
#3. Run tailf-with-colors <filename>
@achristodoulou
Copy link
Author

For more information about bash colors see https://wiki.archlinux.org/index.php/Color_Bash_Prompt

@Loupax
Copy link

Loupax commented May 22, 2015

Here is a forked version that allows you to pass arbitary parameters to the command, instead of being limited to just a filename :)

https://gist.github.com/Loupax/ec45752a5c630f7bda55

@achristodoulou
Copy link
Author

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment