How can I roll over Tomcat 5.5 stderr and stdout files when they get too large/big?

廉价感情. 提交于 2020-01-23 02:48:28

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/5822763/how-can-i-roll-over-tomcat-5-5-stderr-and-stdout-files-when-they-get-too-large-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!