Is there an easier way to rotate logs?

I have various kinds of logs.

I've around 10 glassfish domains.

Each of them have separate logs.

application.log and server.log

The older logs go like this

application.log_2023-10-06 

whereas today's logs go like this

application.log

Then I have some tomcat and java servers as well which have catalina.out and wrapper.log.

wrapper.log is changing its time by itself i.e yesterday's log (today is 10-07) will be wrapper.log_2023-10-06.

But all of catalina.out remains in same file. It contains logs of multiple days, weeks and sometimes months.

Currently I am doing this.

find /path/to/glassfish/domain/logs -mtime +3 -type f -name 'application.log_*' -exec rm {} \;
find /path/to/glassfish/domain/logs -mtime +3 -type f -name 'server.log_*' -exec rm {} \;
find /path/to/java/server/logs -mtime +3 -type f -name 'wrapper.log_*' -exec rm {} \;

And then putting a cronjob to run it at 23:59 everyday.

I am not going to lie, this is really tedious thing. Specially because there are 10 different domains and 5 different java servers and 3 different tomcat servers in this linux server. And I am administering 20+ different servers.

Plus, to add pain to my work, the glassfish domains and tomcat and java servers name are different in each of those servers. Please tell me a good way to logrotate?

I've heard about logrotate but I am not sure how that would be any efficient in my case and how I would use that? I have read about that though.

I'm not doing anything for catalina.out as I got no idea.

Administering logs is tedious if you are serious about it, there is no easy way out. Since most people don't bother to look at logs, only when there is an issue, why make your life difficult?
logrotate does a good job... Give it a try on one of your most irritating logs, find the most suitable configuration, test it suffice for your needs, then decide

2 Likes

Does your gzip have a -k or --keep option?
And do you have GNU/Linux?
Then you can try s.th. like this:

find /path/to/catalina.out -size +100M -exec gzip -k {} \; -exec truncate -s 0 {} \;

Run it at a "quiet" time. A couple of log entries during the compression might get lost.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.