2

We have several Tomcat 7 instances installed on different servers. We sometimes deploy basically the same app to different Tomcats (for different customers) with the only differences being configs. In an effort to standardize logging locations, etc., we are trying to make the apps "universal" so that simply deploying the war file to a Tomcat instance will wire it up automatically so that we don't have to remember to change app for customer 1 and then again for customer 2, etc.

Anyway, in each Tomcat/conf folder, I have added some properties to the end of the catalina.properties file. Example:

# custom logging
log.base=c:/logs/tomcat/myapp
log.file=MYAPP.log

Now, in my application's log4j.cfg file, I have:

log4j.appender.R.File=${log.base}/${log.file}

And in my application's myapp.cfg I have:

logfile=${log.file}

Works great when I deploy. Tomcat puts everything where it should be except what's in the logging.properties file.

That file normally contains:

1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs

But I want to change the ${catalina.base}/logs to use my own ${log.base} variable. But Tomcat (or perhaps log4j?) doesn't recognize this. Instead, it actually creates a directory named "${log.base}" in the Tomcat root folder.

I read that you can declare custom variables in a setenv.bat file. I did that and it still didn't work.

How can I fix this?

BTW, I am using Windows, Tomcat 7 and the Windows service install (with the GUI).

Thanks

cbmeeks
  • 11,248
  • 22
  • 85
  • 136

1 Answers1

5

Set the environment variable JAVA_OPTS in setenv.bat. In this way you give a java VM argument. The following works in setenv.sh in Linux:

export JAVA_OPTS="-Dlog.base=/logs/tomcat/"

Now you should be able to use ${log.base} in logging.properties

The Governor
  • 1,152
  • 1
  • 12
  • 28