WAR 应用程序的日志文件保存在哪里?
我正在尝试在 log4j.properties
中为我的 Web 应用程序 (WAR) 配置日志记录:
log4j.rootCategory=WARN, RF
log4j.appender.RF=org.apache.log4j.RollingFileAppender
log4j.appender.RF.File=???/my-app.log
我应该为 my-app.log
指定什么文件路径?该文件保存在哪里?目前我正在将我的应用程序部署到 Tomcat6,但谁知道将来会发生什么。谁知道将来 Tomcat 将如何配置/安装在另一台计算机上。
I'm trying to configure logging for my web application (WAR), in log4j.properties
:
log4j.rootCategory=WARN, RF
log4j.appender.RF=org.apache.log4j.RollingFileAppender
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最终做的是这样的:
settings.xml
中我定义了一个属性log.dir
log4j.properties
中我定义:log4j.appender.RF.File=${log.dir}/my-app.log
pom.xml
中,我指示 Maven 过滤.properties
文件就是这样。现在,我可以控制目标容器上日志文件的位置,而无需对源代码进行任何更改。
What I finally did is this:
settings.xml
I define a propertylog.dir
log4j.properties
I define:log4j.appender.RF.File=${log.dir}/my-app.log
pom.xml
I instruct Maven to filter.properties
filesThat's it. Now I can control the location of my log files on the destination container without any changes to the source code.
日志记录是一个部署配置描述符,因此您确实无法一概而论。配置取决于主机和项目的其他非功能性要求。
一般来说,在 tomcat 中,我会登录
${catalina.home}/logs/myapp.log
但你可以想象,如果我部署在 weblogic 中,就没有任何catalina.home
因此日志将转到 c:\logs\myapp.log。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 anycatalina.home
so the log will go to c:\logs\myapp.log.我同意@cherouvim 的观点。一般来说,您应该将日志文件放在 web 应用程序之外,并且最好放在容器放置其日志文件的同一位置。
您不想将它们放入 web 应用程序树中,因为如果重新部署您的 web 应用程序,它们将会被破坏。
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.
如果问题是关于您的个人机器,那么这并不重要。将它们放在您方便的地方(例如服务器日志旁边)。
如果问题涉及开发、IST、UAT 等环境,则日志通常应写入单独/专用分区。但是你应该向系统管理员询问这个问题,许多公司都有开发标准、标准化布局。
这是我在黑暗中的尝试,但这是我过去使用过的规范化路径:
/var/log/tomcat//myApp-.log.
而且因为我算命的能力并不比你强,是的,谁知道未来会发生什么:)
这就是配置文件的美妙之处,您可以根据需要配置它......甚至更改它:)
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.
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 :)
That's the beauty of a configuration file, you can configure it as required... and even change it :)