您能让 Tomcat 6 stdout.log 文件表现得像 log4j DailyRollingFileAppender 吗?

发布于 2024-08-17 04:17:41 字数 410 浏览 3 评论 0原文

我们使用的是 Tomcat 6 的 Windows 安装。默认情况下,我们应用程序的 log4j 输出将转到 ${catalina.base}/logs/stdout_.log 文件。该日志文件仅在我们重新启动 Tomcat 时滚动,并且文件名始终包含日期。

我希望它的行为像 DailyRollingFileAppender,它在滚动时重命名文件...这样我就可以打开 Notepad++ 并查看今天的日志,因为 Notepad++ 会记住我昨天打开了同一个文件。 :)

我知道我可以在 log4j 中创建另一个附加程序,但我最终会得到 stdout.log 和另一个日志文件,而且我担心记录到这两个文件会对性能造成轻微影响。我尝试将swallowOutput=true 添加到我的context.xml 但我仍然在stdout.log 中获取所有日志记录。有什么想法吗?

We are using the Windows installation of Tomcat 6. By default, the log4j output for our app goes to the ${catalina.base}/logs/stdout_.log file. This log file only rolls over when we restart Tomcat, and the file name always includes the date.

I would prefer it to behave like a DailyRollingFileAppender, where it renames the file when it rolls over... that way I can just open Notepad++ and see today's logs, since Notepad++ will remember that I opened that same file yesterday. :)

I know I can just create another appender in log4j, but I would end up with the stdout.log and another log file, and I'm afraid there would be a minor performance hit for logging to both files. I've tried adding swallowOutput=true to my context.xml but I still get all logging in stdout.log. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

━╋う一瞬間旳綻放 2024-08-24 04:17:41

您是否尝试过登录 Tomcat 中列出的步骤?如果您按照这些步骤操作,您将在 lib 目录中得到 log4j.properties,您可以根据自己的喜好进行自定义。

Have you tried the steps outlined in Logging in Tomcat? If you follow the steps you'll end up with log4j.properties in the lib directory that you can customize to your heart's content.

鲜肉鲜肉永远不皱 2024-08-24 04:17:41

最大的性能损失是在准备要记录的对象时(您知道,当您执行 logger.info(" Operating on " + myObject.toString + " bla bla bla" ) 然后执行 myObject.toString() 的成本最大)。如果您已经拥有它们,那么登录文件就不是问题。而且log4j确实进行了很好的平衡和优化,它使用缓冲区来写入日志,因此不会对文件系统进行过于频繁的调用。

只需创建另一个附加程序,您将获得与 tomcat 日志和应用程序日志不同的区别。你有多少日志?每天1GB以上你还怕性能损失吗?在测试之前不要假设任何事情。只需进行设置并进行某种性能测试即可。

The biggest performance hit is when preparing objects that you want to log (you know, when you do logger.info(" operating on " + myObject.toString + " bla bla bla" ) then doing myObject.toString() has the biggest cost). If you already have them than loggin to file is not a problem. And log4j is really well balanced and optimized, it uses buffers to write logs, so it do not make too frequent calls to file system.

Just create another appender, you will have a differentation from tomcat logs and your appilcation logs. How many logs do you have? A 1GB a day or more that you are afraid of performance loss? Don't assume anything before testing it. Just set-up, and do some kind of performance test.

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