Skip to content

Instantly share code, notes, and snippets.

@miyako-ep
Last active November 9, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyako-ep/eea65cde5324ed7e79d75db946a2e25d to your computer and use it in GitHub Desktop.
Save miyako-ep/eea65cde5324ed7e79d75db946a2e25d to your computer and use it in GitHub Desktop.
ログを見たりするときに色で出したいスクリプトです、`gawk`依存、基本pipeで使います
#!/usr/bin/gawk -f
BEGIN {}
/DEBUG/ { gsub( "DEBUG", "\033[2;49;94mDEBUG\033[0m"); } # PURPLE
/INFO/ { gsub( "INFO", "\033[2;49;39mINFO\033[0m"); } # SILVER
/NOTICE/ { gsub( "NOTICE", "\033[2;49;92mNOTICE\033[0m"); } # GREEN
/WARNING/ { gsub( "WARNING", "\033[2;49;93mWARNING\033[0m"); } # YELLOW
/ALERT/ { gsub( "ALERT", "\033[2;49;91mALERT\033[0m"); } # ORANGE
/ERROR/ { gsub( "ERROR", "\033[2;49;31mERROR\033[0m"); } # RED
# ip address
match($0, /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { str=substr($0, RSTART, RLENGTH); gsub( str, "\033[2;49;91m"str"\033[0m"); } # ORANGE
/localhost/ { gsub( "localhost", "\033[2;49;91mlocalhost\033[0m"); } # ORANGE
# date
match($0, /[0-9]+-[0-9]+-[0-9]+/) { str=substr($0, RSTART, RLENGTH); gsub( str, "\033[2;49;94m"str"\033[0m"); } # PUARPLE
# time
match($0, /[0-9]+:[0-9]+:[0-9]+/) { str=substr($0, RSTART, RLENGTH); gsub( str, "\033[2;49;96m"str"\033[0m"); } # CYAN
# ansible
/PLAY/ { gsub( "PLAY", "\033[2;49;96mPLAY\033[0m"); } # PURPLE
/TASK/ { gsub( "TASK", "\033[2;49;92mTASK\033[0m"); } # PURPLE
/fatal/ { gsub( "fatal", "\033[2;49;91mfatal\033[0m"); } # PURPLE
{ print $0; }
{ fflush(); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment