4

I want to manage log rotation on my server using logrotate, however Tomcat performs its own log rotation which interacts badly with logrotate, and I can't find a way to turn it off. My Tomcat instance currently produces 5 types of log:

  • catalina.2018-01-17.log
  • mysite_access.2018-01-17.log
  • localhost.2018-01-17.log
  • host-manager.2018-01-17.log
  • manager.2018-01-17.log

After some googling I have discovered that I can disable rotation for the 'mysite' logs by adding rotatable="false" into the appropriate <Value> element in server.xml, but none of the other logs have corresponding <Value> elements.

The logs seems to be configured by the logging.properties file, but I can't find a 'turn rotation off' option for this file. Can anyone help? I'm using Tomcat 8.5

7
+50

You're probably using JULI logging as the default in your tomcat instance. Try this

1catalina.org.apache.juli.FileHandler.rotatable = false

In logging.properties.

There are some samples online if you search for that property.

If you're not using those logs for anything, you can just remove or rename off the logging.properties file to stop using JULI logging.

2

I think you're coming to it from the wrong perspective. There is nothing inherently novel about logrotate, in fact, it usually gets run from cron once a day, which can result in funny situations where you have no idea why your logrotate directions aren't working.

The best approach here may be to leave the defaults of tomcat as-is (which, in fact, are more friendly for various backup purposes, for example), and do the rotation with a simple script that uses file modification time to perform the rotation (e.g., find /var/tomcat/logs/ -mtime +5 -name "*.log" -exec echo rm {} \;, remove echo for the real thing).

Per related question, you can also configure the above find snippet within the lastaction / endscript directives of logrotate, or, better yet, put it directly into cron to run on your own time.

Other references:

1

Just send logs to syslog, and write the logfiles with syslog then rotate as you wish.

  • 100 times this. But if you don't want to (or can't...) use logrotate, you can also use log4j 2 if you want "better" logging. – Lenniey Jan 18 '18 at 10:31
  • thanks, but I'm really looking for a simple way to do this using just tomcat configuration - it seems crazy that there is no way to change this behaviour especially since it breaks logrotate so badly – codebox Jan 19 '18 at 7:49
  • While I 100% agree with @Lenniey, I am not sure, how could you send the tomcat logs to syslog, or how could it be done easily. Java doesn't support unix sockets, and syslog happens with unix sockets (by default). – peterh - Reinstate Monica Oct 12 '18 at 17:58
  • To get tomcat to log in system log, 1) a JNI-based (-> platform-dependent) addon should be installed, or syslogd should listen on a networked socket, too 2) a juli jar should be installed in the tomcat, and properly configured, which logs there. As far I know, nobody developed it until now. – peterh - Reinstate Monica Oct 12 '18 at 18:31
  • @Lenniey I think, you have probably set up only the application log, but not the tomcat log. With it, you miss a lot of important debug/troubleshooting information. – peterh - Reinstate Monica Oct 12 '18 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.