TomEE Logging Configuration

Because TomEE comes with a java.util.Logging Logger which I really dislike, I decided to change the logger to log4j through slf4j. Here are the steps to achieve this:

  • Create a folder _tomee_/bin/log and place the following libraries in it: jul-to-slf4j-1.7.5.jar, log4j-1.2.17.jar, slf4j-api-1.7.5.jar, slf4j-log4j12-1.7.5.jar
  • Remove slf4j-*jdk*.jar and slf4j-*api*.jar from _tomee_/lib
  • Create a log4j.properties file in _tomee_/bin/log/config
  • Create a file named setenv.sh in _tomee_/bin and place the following code in it:

CLASSPATH=$CATALINA_HOME/bin/log/jul-to-slf4j-1.7.5.jar:
$CATALINA_HOME/bin/log/log4j-1.2.17.jar:
$CATALINA_HOME/bin/log/slf4j-api-1.7.5.jar:
$CATALINA_HOME/bin/log/slf4j-log4j12-1.7.5.jar:
$CATALINA_HOME/bin/log/config/

  • Replace the content of _tomee_/conf/logging.properties with the following

handlers = org.slf4j.bridge.SLF4JBridgeHandler

  • Now you can run TomEE from shell with log4j logger. But you can’t start it from eclipse anymore.
  • To get it working in eclipse add the 4 jars and the config folder to the server classpath (External Jars / Advanced => External Folder)
  • Eclipse ignores the logging.properties file of TomEE so you have to add the following to VM arguments of the server:

-Djava.util.logging.config.file=”_tomee_/conf/logging.properties”
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

EDIT: See http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j

Leave a Comment