views:

490

answers:

2

With the following settings:

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=test.log
log4j.appender.file.threshold=info
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

Where does the test.log file locate in a java web application?

Thanks.

+1  A: 

If you do specify a relative name, it is the working directory of your application server.

ftl
How do I have to do to set it to somewhere inside my web application, given the fact that I don't know the path from my application server to my web application?Thanks again.
Winston Chen
You can specify in Web.xml the path of the logs <init-param> <!-- The Path for the LOG directory of PWM where all log files will be stored. --> <param-name>log.path</param-name> <param-value>pwm\logs</param-value> </init-param>
GustlyWind
Thanks. Does this mean that once I put the tags into web.xml and the properties file in src, the location will be myapp\logs\test.log?
Winston Chen
+1  A: 

You can specify this as a system property and get it Via System.getProperty()

what we do is define a property as logroot ie.; -Dlogroot="PATH_TO_LOGS_FOLDER"

EDIT: FWIW System.getProperty() checks for checkPropertyAccess as well as checkPermission in case of lack of permissions.

hope that helps

Narayan
Thanks. I have two questions on this.1. Where should I define 'logroot="PATH_TO_LOGS_FOLDER"'? in log4j.properties? or do you have a reference link for this?2. is "PATH_TO_LOGS_FOLDER" a relative path to my webapp root?Thanks a lot.
Winston Chen
If you are using IDE,typically it is set as a property in the Tomcat->optional vm arguements
Narayan
reg 2) it can be absolute/relative path, FWIW, we use to set it as a directory in our workspace(MyEclispe IDE) thus we create a directory inside our web-app root called as logs, it goes there(-Dlogroot="c:/workspace/logs"), thus can access the logroot using the above method in the post
Narayan