Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log rotation with logrotate and log4j

Status
Not open for further replies.

forrie

MIS
Mar 6, 2009
91
US
We have an application server that uses a minimal config for log4j to rotate files. The rest (due to political reasons) needs to be handled otherwise.

I'm running into a problem with logrotate, in that I end up with several *.gz.gz.gz files. Each file is logged in a custom format, like:

appsvr.log.2010-02

It's not enough to put *.log in the logrotate config, and * has negative results.

So my question is how to get around this -- should I put in a regex in the logrotate configuration? (if it would support it) Here's what we have:

/usr/tomcat/logs/* /usr/tomcat/appsvr_logs/* {
rotate 5
missingok
compress
notifempty
size 10M
sharedscripts
prerotate
/sbin/service tomcat5 stop
sleep 7
endscript
postrotate
/sbin/service tomcat5 start
endscript
}


Obviously the * is incorrect - and that's my bad. It was previously *.log which wasn't picking up the above-mentioned filenames and thus nothing was being rotated.

I otherwise end up with incidents like the other day where we have a full filesystem because the logs were never rotated. I know I could run a simple "find" but that negates the point of having logrotate.


Thanks.
 
This isn't my area of expertise. I have an idea, although there is probably a better way. You could create a script that regenerates the configuration file with the current list of logs files. Then just run that script before you run logrotate. Not exactly efficient, but I think it would solve your problem.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Just use:

Code:
/usr/tomcat/logs/*.log.[0-9][0-9][0-9][0-9]-[0-9][0-9] /usr/tomcat/appsvr_logs/*.log.[0-9][0-9][0-9][0-9]-[0-9][0-9]   {

Annihilannic.
 
Thank you, Annihilannic... I think this will solve the problem. I also had to add /usr/tomcat/logs/*.log and /usr/tomcat/appsvr_logs/*.log to that string, as the active logfile is named that (not my choice).

I put it in the logrotate.d config and will see how it works tonight :)

Thank you again.
 
So I have yet another variable to insert. The log files that are stored in the odd YYYY-XX format look like this:

appsvr.log.2008-51
appsvr.log.2009-24
appsvr.log.2009-49
kodo.log.2008-39
kodo.log.2010-13

( etc )

That last number being an incremental. So logically how can I set logrotate to only keep x number of these YYYY-XX files? I think I may be hitting a block in terms of functionality, or at least where I might need a pre- script to sort them numerically?

 
I noticed last night that the regex did not affect the log rotation, only the *.log files got rotated. FYI.

I may just be running into a functional limitation of logrotate, where I'm going to have to write some clever post scripts...
 
Are any of these files over 10M? That might explain why logrotate did nothing with them (the size 10M rule).

Let's go back to basics... as I think it may be a flawed plan to use logrotate to "rotate" logs that are already being rotated by the application.

What does the -XX mean? Is that the week number? What exactly do you want to achieve here? For example, with the pretty old appsvr.log.2008-51 file, what do you expect logrotate to do? If you just want the older files compressed, a find /usr/tomcat/logs/*.log.[0-9][0-9][0-9][0-9]-[0-9][0-9] -type f -mtime +30 -exec gzip {} \; would be a much neater solution, plus another similar job to remove the really old files.

Otherwise, if the problem is that the log files are filling too rapidly and weekly rotation is not enough, then you could reasonably consider using logrotate, but only on the currently active log file; once it has been rotated then there should be no more work to do.

I hope that helps.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top