tomcat logging using log4j

In normal install tomcat use JULI for logging and this logging framework has issues on some advance rotation log file  configuration. I got issue with my hard disk always full after tomcat run for a couple of week cause log files. So i wonder if i can limit number of log files generate and tomcat reuse the old one when limit is reach.
After some research i find a solution. Tomcat allow us integration with log4j logging framework so we can handle above issue so easy.
If you have same problem i can guide you through.
Steps to make Tomcat work with log4j

We download two files from extras on tomcat download section

  • tomcat-juli.jar
  • tomcat-juli-adapters.jar

Copy tomcat-juli.jar to $CATALINA_HOME\bin to replace old one

Copy tomcat-juli-adapters.jar to $CATALINA_HOME\lib

Delete in $CATALINA_HOME\conf

Create in $CATALINA_HOME\libs. This is sample of mine:

log4j.rootLogger=INFO, CATALINA

log4j.appender.CATALINA.layout.ConversionPattern=%d [%t] %-5p %c- %m%n

Download log4j version greater than 1.2 and copy to $CATALINA_HOME\lib

After that restart tomcat.


Leave a Reply