Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set CATALINA_HOME in log4j.xml?

Tags:

java

tomcat

log4j

I need something like this:

"param name="File" value="${CATALINA_HOME}/logs/log4j.log"

I saw a lot of similar questions, but there is no working solutions.

like image 552
trierra Avatar asked May 26 '12 20:05

trierra


2 Answers

For Tomcat 6.0 or newer use catalina.base (rather than catalina.home):

param name="File" value="${catalina.base}/logs/log4j.log"

Depending on the host system, the two may be different, for example:

catalina.home: /usr/share/tomcat7
catalina.base: /var/lib/tomcat7 

Under catalina.home there's the bin folder.

Under catalina.base there are conf, logs, webapps and other folders/links.

Tomcat uses catalina.base itself to configure the logging directory - see conf/logging.properties where it says:

1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
like image 145
Markus Pscheidt Avatar answered Oct 07 '22 00:10

Markus Pscheidt


param name="File" value="${catalina.home}/logs/log4j.log"

The catalina.home property is already made available by Tomcat.

Find a (very) brief example on the Tomcat 5.5 logging page and additional detail in the following SO question:

Log4j, configuring a Web App to use a relative path

like image 25
Ryan Stewart Avatar answered Oct 06 '22 23:10

Ryan Stewart