本文介绍了当 Tomcat 5.5 stderr 和 stdout 文件变得太大/太大时,如何翻转它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找出一种方法来获取 Tomcat 5.5 stderr 和 stdout 日志文件,并在它们变得太大时将它们翻转过来,但我一直无法这样做.现在,请理解这不适用于 Web 应用程序日志记录.这只是Tomcat自动创建的stdout和stderr日志.同样,它们变得太大了,当它们变得太大和/或在某个时间间隔(即每天、每小时)时,我只需要一种方法来滚动它们.

I have been trying to figure out a way to take the Tomcat 5.5 stderr and stdout log files and roll them over when they get too large, but I have been unable to do so. Now, please understand this is NOT for web app logging. This is just the stdout and stderr logs that are automatically created by Tomcat. Again, they get too large, and I just need a method to roll them over when they get too large and/or on a time interval (i.e. every day, every hour).

我尝试使用 log4j,但这似乎适用于应用程序日志记录,而不适用于 tomcat.我发现有一种方法表明它可以使用 og4j 重定向标准输出和标准错误(http://sysgears.com/articles/how-to-redirect-stdout-and-stderr-writing-to-a-log4j-appender#comment-749),我在这个网站上写了几个问题,详细说明了我的困境,但我一直无法让它工作.如果我可以让该方法起作用,或者如果有 log4j 之外的另一种方法,我将不胜感激.

I tried using log4j, but that appears to be geared for application logging, not so much for tomcat. There was a method I found that states it can redirect stdout and stderr using og4j (http://sysgears.com/articles/how-to-redirect-stdout-and-stderr-writing-to-a-log4j-appender#comment-749), and I wrote a couple of questions on this site detailing my plight with it, but I have been unable to get it to work. If I can get that method to work, or if there's another way that is outside of log4j, I would appreciate it.

此外,是否可以自己在 Java 或 perl 中滚动文件?作为测试,我尝试删除正在写入的文件,但是,当然,我不能.这些文件被 Tomcat 锁定.流程是这样的:

Moreover, would it be possible to roll over the files myself in, say, java or perl? As a test, I tried deleted the files, as they were being written to, but, of course, I couldn't. The files were locked by Tomcat. The process would be this:

从Tomcat进程中解锁文件检查尺寸是否太大"如果是,保存并关闭文件,用新文件名写入一个新文件(即 stderr01012011_1.log)将新文件锁定到 Tomcat 进程

Unlock the file from Tomcat processCheck if size is "too big"If it is, save and close file, write a new one with new filename (i.e. stderr01012011_1.log)Lock new file to Tomcat process

这听起来像很多工作,甚至可能都不可行,但如果我无法让 log4j 方法工作,我该怎么办?谢谢.

This sounds like a lot of work and may not even be doable, but if I can't get the log4j method to work, what can I do? Thank you.

我希望 Apache 有内置的东西来翻转 stderr 和 stdout 日志文件.

I wish Apache had something built-in to rollover stderr and stdout log files.

推荐答案

您可以使用带有copytruncate"选项的 logrotate.看看这里:如何旋转Tomcat catalina.out

You can use logrotate with "copytruncate" option. Take a look here: How to Rotate Tomcat catalina.out

这篇关于当 Tomcat 5.5 stderr 和 stdout 文件变得太大/太大时,如何翻转它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 18:52