Purpose
The purpose of this document is to explain you the steps to enable the log4j logging in apache tomcat as you may know that tomcat used system logging API i.e. java.util.logging for its internal logging.
In one of my project I came across such scenario where I need to implement the log4j logger for tomcat logs as well as application [grails ] log.
So below are the steps we perform to set up log4j logging on tomcat 7 for grails 1.3.7 application.
1) Move existing tomcat conf/logging.properties to some other name
mv logging.properties logging.properties-back
2) Download Tomcat juli adapters library to tomcat/lib/
The purpose of this document is to explain you the steps to enable the log4j logging in apache tomcat as you may know that tomcat used system logging API i.e. java.util.logging for its internal logging.
In one of my project I came across such scenario where I need to implement the log4j logger for tomcat logs as well as application [grails ] log.
So below are the steps we perform to set up log4j logging on tomcat 7 for grails 1.3.7 application.
1) Move existing tomcat conf/logging.properties to some other name
mv logging.properties logging.properties-back
2) Download Tomcat juli adapters library to tomcat/lib/
wget http://mirror.sdunix.com/apache/tomcat/tomcat-7/v7.0.28/bin/extras/tomcat-juli-adapters.jar
3) Download Tomcat juli library to tomcat/lib/
wget http://mirror.sdunix.com/apache/tomcat/tomcat-7/v7.0.28/bin/extras/tomcat-juli.jar
4) To make log4j work with grails app using tomcat-juli.jar we need
org\apache\juli\logging\UserDataHelper.java which is not available in extra/ tomcat-juli.jar [but available in default tomcat jar] so we make a patch called tomcat-log4j-patch.jar. contain UserDataHelper.class [NOT UPLOADED] . Copy this jar in tomcat lib folder
5) Copy log4j.jar in tomcat lib folder
6) Open the catalina.sh and find juli LogManager config section. In else part add the log4j.xml path
#Set juli LogManager config file if it is present and an override has not been issued
if [ -z "$LOGGING_CONFIG" ]; thenif [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
else
LOGGING_CONFIG="-Dlog4j.configuration=file://$CATALINA_BASE/lib/log4j.xml" fi
7) Restart the server
No comments:
Post a Comment