Skip to content

Instantly share code, notes, and snippets.

@zakmac
Last active November 24, 2023 20:43
Show Gist options
  • Save zakmac/8135974d0ade78483e3b to your computer and use it in GitHub Desktop.
Save zakmac/8135974d0ade78483e3b to your computer and use it in GitHub Desktop.
Add color to your Catalina output logs for [info, warn, error, severe, startup]
#!/bin/bash
# ABOUT
# Add color to your Catalina output logs for [info, warn, error, severe, startup]
# - This isn't the smartest, so if there is a match for any of the listed statuses in an
# output you can bet it'll be colorized
# USAGE
# catalina run 2>&1 | bash ~/colorize-tomcat-logs.sh
success=$(tput bold;tput setaf 2)
successCondition=*INFO:" "Server" "startup*
info=$(tput setaf 6)
infoCondition=*INFO*
warn=$(tput setaf 3)
warnCondition=*WARN*
error=$(tput setaf 1)
errorCondition=*ERROR*
severe=$(tput bold;tput setaf 1)
severeCondition=*SEVERE*
default=$(tput sgr0)
while read line; do
if [[ $line == $successCondition ]]
then
echo $line | sed -e "s/\($1\)/$success/"
elif [[ $line == $infoCondition ]]
then
echo $line | sed -e "s/\($1\)/$info/"
elif [[ $line == $warnCondition ]]
then
echo $line | sed -e "s/\($1\)/$warn/"
elif [[ $line == $errorCondition ]]
then
echo $line | sed -e "s/\($1\)/$error/"
elif [[ $line == $severeCondition ]]
then
echo $line | sed -e "s/\($1\)/$severe/"
else
echo $line
fi
printf $(tput sgr0)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment