11

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.

trierra
  • 279
  • 1
  • 2
  • 8

3 Answers3

15

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
Markus Pscheidt
  • 6,853
  • 5
  • 55
  • 76
10

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

Community
  • 1
  • 1
Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
4

You can do the following:

  1. send the CATALINA_HOME as an environment variable using -D option. You just have to run

set JAVA_OPTS=%JAVA_OPTS% -DCATALINA_HOME=%CATALINA_HOME% if you are on windows or export JAVA_OPTS=${JAVA_OPTS} -DCATALINA_HOME=$CATALINA_HOME for unix.

Now just use ${CATALINA_HOME} into your log4j configuration file and this should work.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • No. I did it first! But i have gotten an exception. I can't access from configuration file to system environment! – trierra May 27 '12 at 06:57
  • I'm not sure why you'd define another one, when it's already there. See [my answer](http://stackoverflow.com/a/10769833/839646). – Ryan Stewart May 28 '12 at 16:02