Skip to content

Instantly share code, notes, and snippets.

@SimplyInk
Forked from jdanbrown/log-color
Last active February 10, 2017 09:57
Show Gist options
  • Select an option

  • Save SimplyInk/a30f08739cec2fef79e6ee17f38d5af3 to your computer and use it in GitHub Desktop.

Select an option

Save SimplyInk/a30f08739cec2fef79e6ee17f38d5af3 to your computer and use it in GitHub Desktop.
log4j logs in color!
#!/bin/bash -eu
#
# Color log4j-style logs for easier visual parsing.
#
# Usage:
# put this file in /usr/local/bin
# chmod +x log-color
# tail foo.log | log-color
black="`tput setaf 0; tput bold`"
red="`tput setaf 1; tput bold`"
green="`tput setaf 2; tput bold`"
yellow="`tput setaf 3; tput bold`"
blue="`tput setaf 4; tput bold`"
magenta="`tput setaf 5; tput bold`"
cyan="`tput setaf 6; tput bold`"
white="`tput setaf 7; tput bold`"
off="`tput sgr0`"
exec sed -r "
# Timestamps
s/^\[[0-9]4[^]]*\]/$black\\0$off/
s/^[0-9]4-[0-9:,/ -]*/$black\\0$off/
# Log levels
s/\\b(FATAL|CRITICAL)\\b/$magenta\\0$off/g
s/\\bERROR\\b/$red\\0$off/g
s/\\bWARN(ING)?\\b/$yellow\\0$off/g
s/\\bINFO\\b/$green\\0$off/g
s/\\bDEBUG\\b/$blue\\0$off/g
s/\\bTRACE\\b/$cyan\\0$off/g
# Grouped things
s/ \[[^]]+\] \S+ - /$black\\0$off/
s/ \([a-zA-Z_][a-zA-Z0-9_$.:]*\)$/$black\\0$off/
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment