I am writing Tomcat log with this setting:

  • Log configured using an AccessLogValve in server.xml

    Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/access"
    prefix="access" suffix=".log" pattern="common" rotatable="false"
  • Use logrotate to rotate the log file daily and remove old log files.

    /app/logs/access/access.log {
        rotate 14
        maxage 14
        dateyesterday }

The strange thing is that every day the log file is changed to a new name by logrotate, for example access.log-20171222, and a new log file access.log is created. However, Tomcat still writes log to the renamed file.

My solution now is adding the option copytruncate to the configuration file of logrotate. However, with this option, there is a chance of losing some log at the time of truncating.

Can anyone suggest a better solution?

Thank you.


According to this documentation you should keep the rotatable option as true (default) so that it does not write always to the same file. Also you can format the filename string to a fixed value, so that you do not get dates on them. Just be sure to run logrotate before the internal rotation so that the new log does not risk overwriting the last (as it gets renamed).

  • It seems to be a good idea. I will try and tell you the result :) – thanh dat tang Dec 22 '17 at 7:42
  • It does not work because in the documentation of Tomcat, it say fileDateFormat Allows a customized timestamp in the access log file name. The file is rotated whenever the formatted timestamp changes. The default value is .yyyy-MM-dd. If you wish to rotate every hour, then set this value to .yyyy-MM-dd.HH. The date format will always be localized using the locale en_US. So the file name always has date in it – thanh dat tang Dec 27 '17 at 10:07
  • Indeed... Perhaps you can get something better customizable with login or a renaming script with the logrotate routine... – Zip Dec 27 '17 at 10:38
  • Sorry, didn't mean login, meant log4j – Zip Dec 27 '17 at 10:54

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.