Where to keep log files of WAR application?
I'm trying to configure logging for my web application (WAR), in log4j.properties
:
log4j.rootCategory=WARN, RF
log4j.appender.RF=org.apache.log4j.RollingFileAppen开发者_开发问答der
log4j.appender.RF.File=???/my-app.log
What file path I should specify for my-app.log
? Where to keep this file? Currently I'm deploying my application to Tomcat6, but who knows what happens in the future. And who knows how exactly Tomcat will be configured/installed on another machine, in the future.
What I finally did is this:
- In continuous integration
settings.xml
I define a propertylog.dir
- In
log4j.properties
I define:log4j.appender.RF.File=${log.dir}/my-app.log
- In
pom.xml
I instruct Maven to filter.properties
files
That's it. Now I can control the location of my log files on the destination container without any changes to the source code.
Logging is a deployment configuration descriptor so you really cannot generalize. Configuration depends on the host machine and other, non functional requirements of the project.
Generally in tomcat I log into ${catalina.home}/logs/myapp.log
but as you can imagine if I deploy in weblogic there isn't any catalina.home
so the log will go to c:\logs\myapp.log.
I agree with @cherouvim. In general, you should put the log file outside of the webapp, and preferably in the same place that the container puts its log file.
You don't want to put them in the webapp tree, because they will get clobbered if your webapp is redeployed.
What file path I should specify for my-app.log? Where to keep this file?
If the question is about your personal machine, it doesn't really matter. Put them where it's handy for you (e.g. next to the server logs).
If the question is about a development, IST, UAT, etc environment, logs should typically be written to a separate/dedicated partition. But you should ask this question to the sysadmins, many companies have exploitation standard, standardized layouts.
Currently I'm deploying my application to Tomcat6, but who knows what happens in the future.
This is a shot in the dark since but here is a normalized path I've used in the past: /var/log/tomcat/<PROJECTNAME>/myApp-<instance-#>.log
.
And because I'm not better than you at fortune-telling, yeah, who knows what happens in the future :)
And who knows how exactly Tomcat will be configured/installed on another machine, in the future.
That's the beauty of a configuration file, you can configure it as required... and even change it :)
精彩评论