当 Tomcat 5.5 stderr 和 stdout 文件变得太大时,如何滚动它们?
我一直在试图找出一种方法来获取 Tomcat 5.5 stderr 和 stdout 日志文件,并在它们变得太大时将它们滚动,但我一直无法这样做。现在,请理解这不适用于网络应用程序日志记录。这只是 Tomcat 自动创建的 stdout 和 stderr 日志。同样,它们变得太大,我只需要一种方法在它们变得太大和/或在某个时间间隔(即每天、每小时)时将它们翻转。
我尝试使用 log4j,但它似乎适合应用程序日志记录,而不适合 tomcat。我发现有一种方法,它可以使用 og4j 重定向 stdout 和 stderr (http://sysgears.com/articles/how-to-redirect-stdout-and-stderr-writing-to-a-log4j-appender#comment -749),我在这个网站上写了几个问题,详细说明了我的困境,但我一直无法让它发挥作用。如果我能让该方法起作用,或者如果有 log4j 之外的另一种方法,我将不胜感激。
此外,是否可以自己使用 java 或 perl 来滚动文件?作为测试,我尝试删除正在写入的文件,但是,当然,我不能。文件被 Tomcat 锁定。该过程将是这样的:
从 Tomcat 进程解锁文件 检查尺寸是否“太大” 如果是,保存并关闭文件,用新文件名写入一个新文件(即 stderr01012011_1.log) 将新文件锁定到 Tomcat 进程
这听起来工作量很大,甚至可能无法实现,但如果我无法使 log4j 方法发挥作用,我该怎么办?谢谢。
我希望 Apache 有内置的东西来翻转 stderr 和 stdout 日志文件。
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).
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.
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:
Unlock the file from Tomcat process
Check 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
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.
I wish Apache had something built-in to rollover stderr and stdout log files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 logrotate 与“copytruncate”选项一起使用。看一下这里:如何轮换 Tomcat catalina.out
You can use logrotate with "copytruncate" option. Take a look here: How to Rotate Tomcat catalina.out