3

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 {
        daily
        dateext
        missingok
        rotate 14
        maxage 14
        compress
        delaycompress
        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.

1 Answer 1

1

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).

4
  • It seems to be a good idea. I will try and tell you the result :) Commented Dec 22, 2017 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 Commented Dec 27, 2017 at 10:07
  • Indeed... Perhaps you can get something better customizable with login or a renaming script with the logrotate routine...
    – Zip
    Commented Dec 27, 2017 at 10:38
  • Sorry, didn't mean login, meant log4j
    – Zip
    Commented Dec 27, 2017 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .