Adding some color to a console output is always nice. Here how to do with TomEE.
Under Unix OS it is not so complicated to add some colors to TomEE (it works for Tomcat too).
First create a small java project, add to the classpath jlibs-core. With maven you’ll probably add something like:
<dependencies> <dependency> <groupId>jlibs</groupId> <artifactId>jlibs-core</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <repositories> <repository> <id>jlibs-repository</id> <name>JLibs Repository</name> <url>http://flightofstairs.org/nexus/content/repositories/jlibs</url> <layout>default</layout> </repository> </repositories>
Then create a small class to force the formatter of the handler:
package org.apache.openejb.log.juli; import java.util.logging.ConsoleHandler; import jlibs.core.util.logging.AnsiFormatter; public class ColorConsoleHandler extends ConsoleHandler { public ColorConsoleHandler() { setFormatter(new AnsiFormatter()); } }
Then edit $CATALINA_BASE/conf/logging.properties to replace java.util.logging.ConsoleHandler by our brand new Handler:
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, org.apache.openejb.log.juli.ColorConsoleHandler .handlers = 1catalina.org.apache.juli.FileHandler, org.apache.openejb.log.juli.ColorConsoleHandler
And finally edit $CATALINA_HOME/bin/catalina.sh to add jlibs-core and our jar to the JVM classpath.
# Add tomcat-juli.jar to classpath # tomcat-juli.jar can be over-ridden per instance if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar:$CATALINA_BASE/bin/jlibs-core.jar:$CATALINA_BASE/bin/my-juli.jar else CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar:$CATALINA_HOME/bin/jlibs-core.jar:$CATALINA_HOME/bin/my-juli.jar fi
Then simply restart using:
$CATALINA_BASE/bin/catalina.sh run
And your logs should be in color.
Note jlibs ansi colors are configurable through a file (see jlibs).
Easy no?
Note: for a real usage i guess you’ll update the formatter to get a format closer to SimpleFormatter.