WAR 应用程序的日志文件保存在哪里?

发布于 2024-10-02 07:35:18 字数 340 浏览 1 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小情绪 2024-10-09 07:35:18

我最终做的是这样的:

  1. 在持续集成settings.xml中我定义了一个属性log.dir
  2. log4j.properties中我定义:log4j.appender.RF.File=${log.dir}/my-app.log
  3. pom.xml 中,我指示 Maven 过滤 .properties 文件

就是这样。现在,我可以控制目标容器上日志文件的位置,而无需对源代码进行任何更改。

What I finally did is this:

  1. In continuous integration settings.xml I define a property log.dir
  2. In log4j.properties I define: log4j.appender.RF.File=${log.dir}/my-app.log
  3. 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.

治碍 2024-10-09 07:35:18

日志记录是一个部署配置描述符,因此您确实无法一概而论。配置取决于主机和项目的其他非功能性要求。

一般来说,在 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 any catalina.home so the log will go to c:\logs\myapp.log.

白芷 2024-10-09 07:35:18

我同意@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.

梦行七里 2024-10-09 07:35:18

我应该为 my-app.log 指定什么文件路径?该文件保存在哪里?

如果问题是关于您的个人机器,那么这并不重要。将它们放在您方便的地方(例如服务器日志旁边)。

如果问题涉及开发、IST、UAT 等环境,则日志通常应写入单独/专用分区。但是你应该向系统管理员询问这个问题,许多公司都有开发标准、标准化布局。

目前我正在将应用程序部署到 Tomcat6,但谁知道将来会发生什么。

这是我在黑暗中的尝试,但这是我过去使用过的规范化路径:/var/log/tomcat//myApp-.log.

而且因为我算命的能力并不比你强,是的,谁知道未来会发生什么:)

谁知道将来 Tomcat 将如何配置/安装在另一台计算机上。

这就是配置文件的美妙之处,您可以根据需要配置它......甚至更改它:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文