1

The default Tomcat 8.5 configuration outputs the contents of stdout & stderr to $CATALINA_HOME/logs/catalina.out (and catalina.err if specified in the startup parameters) when running as a daemon. In these files are low-level system messages, startup/shutdown output, and stack traces for errors. Unfortunately, these files are overwritten when Tomcat is restarted. I have forgotten this fact on more than one occasion, when we were having an issue and my first thought was to bounce the app server. When I did that, the prior contents of catalina.out were gone, and we can't then go back through the logs looking for a root cause of the issue. Is there a way to save me and other admins from ourselves and append to catalina.out/.err on startup instead of overwriting it?

I believe that the "correct" answer would be to implement proper error handling and separate logging for the applications being served, but it seems like we should be able to take advantage of this built-in facility with a simple config change, rather than try to make modifications to third party application code for which the source is unavailable.

Also, in our case, logrotate is taking care of rotating catalina.out weekly, so I am not worried about the file getting too large. I thought about maybe calling logrotate in shutdown.sh, but we also have logrotate doing log cleanup; if we want to be able to have more than one log archived per day we would have to break the logrotate naming convention for the shutdown logs, which would then mean the old logs created as a result of shutdown would never get cleaned up, if I understand correctly.

Adri C
  • 21
  • 6
  • Have you tried setting up ```java.util.logging.FileHandler.append = true``` in logging.properties? – Renjith Mar 28 '23 at 19:41
  • I was searching for such a property but could not find it in https://tomcat.apache.org/tomcat-10.1-doc/api/org/apache/juli/FileHandler.html. Surprised that this one should apply (Tomcat's FileHandler does not inherit): https://docs.oracle.com/en/java/javase/11/docs/api/java.logging/java/util/logging/FileHandler.html – Queeg Mar 28 '23 at 20:24

1 Answers1

1

when [Tomcat] running as a daemon.

Assuming you are using jsvc, there does not appear to be an option for appending to log files instead of overwriting them. You could file an enhancement request against the Commons project to add that capability. It does not seem like a difficult thing to implement.

I believe that the "correct" answer would be to implement proper error handling and separate logging for the applications being served[...]

I agree. Writing to stdout is not a great practice and, as you see, can cause some problems that you have to work hard to get around. It would be better to log to a real logging framework which already knows how to append, rotate, etc. and not have to cobble-together your own ad-hoc set of tools to replicate this capability which already exists.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77