views:

2560

answers:

4

Hi, I have the following line in my log4j.properties file:

log4j.appender.logfile.File=MyApplication.log

My log file appears in MyDomain/config directory, but I would like it to land in the MyDomain/logs directory. How can I achieve that? I am not allowed to modify the startserv script.

Thanks in advance for your help!

+2  A: 

You need to specify an absolute path, not a relative one (assuming Unix paths):

log4j.appender.logfile.File=/path/to/MyDomain/logs/MyApplication.log
Vinay Sajip
+1  A: 

The following is possible in Tomcat, perhaps Glassfish sets a similar environment variable pointing to it's filesystem location:

log4j.appender.logfile.File=${catalina.home}/logs/MyApplication.log

${catalina.home} is an environment/system property set by Tomcat pointing to it's install directory. Log4j is capable of expanding these, at least in the PropertyConfigurer.

matt b
It's better to use catalina.base instead of catalina.home, it's required if your tomcat installation is split into a read-only global part and per-tomcat-instance writable directories (where the webapp and logs directories are). It appears (based on googling) that glassfish also defines the catalina.base property.
Stefan L
+1  A: 

In fact, it is log4j who resolves the variable ${catalina.home}, Glassfish declares ${catalina.home} as ${com.sun.aas.instanceRoot} that points to path/to/MyDomain/

You can declare any variable in GF environment and put it on log4j.properties, log4j will parse them when log4j is configured.

That is really useful to set server based logging configuration parameters, using same log4.properties for test and deployment

Herme
A: 

You can set the appender to use the ${com.sun.aas.instanceRoot}, but unlike some other comments it should be:

log4j.appender.logfile.File=${com.sun.aas.instanceRoot}/logs/MyApplication.log

This is the correct location for logs in the ../domains/domain{x}/logs directory.

John Yeary
Note that I couldn't get this working for Apache Tomcat 5.5, it's just for Glassfish presumably.
ian_scho