Skip to content

Instantly share code, notes, and snippets.

@miyako-ep miyako-ep/colorlog
Last active Nov 9, 2017

Embed
What would you like to do?
ログを見たりするときに色で出したいスクリプトです、`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
You can’t perform that action at this time.