tags:

views:

274

answers:

2

Hi,

I'd like my web app to log into files with this path: webapp/logs/

I can set the absolute path in the log4j.properties file, but the production environment's directory structure will be different. Is there any way I could do it?

Here is how I do:

log4j.appender.f=org.apache.log4j.RollingFileAppender
log4j.appender.f.layout=org.apache.log4j.PatternLayout
log4j.appender.f.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.f.File=log.out
log4j.appender.f.MaxFileSize=100KB

This is printing logs into a file named log.log in my eclipse directory (c://eclipse). I'm using Tomcat 6.

+1  A: 

log4j is capable of expanding system properties, so if your production environment sets a property for the directory which you would like to place the log files in, you can reference it from the log4j.properties file.

For example, we deploy webapps on Tomcat as well. Tomcat sets up a system property named catalina.home which points to the Tomcat home directory. A log4j configuration that looks like this:

 log4j.appender.f.File = ${catalina.home}/logs/myapp.log

Will result in the myapp.log file being stored in the logs directory under the Tomcat install directory.

matt b
thank you very much!
Bob
A: 

Hello, i have question..Is it the log (myapp.log) will be replaced daily? if it so, how do i create log daily ex: myapp-2010-07-10.log. And in the next day, file log will be created as myapp-2010-07-11.log?

thanks

maminx