How can I roll over Tomcat 5.5 stderr and stdout files when they get too large/big?
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 someth开发者_运维问答ing built-in to rollover stderr and stdout log files.
You can use logrotate with "copytruncate" option. Take a look here: How to Rotate Tomcat catalina.out
精彩评论