Tomcat8 on Ubuntu .log.gz already exists not overwritten

别来无恙 提交于 2019-12-11 02:12:29

问题


On our Tomcat servers I regularly see warnings like below:

/etc/cron.daily/tomcat8:
gzip: /var/log/tomcat8/app1/app1.log.gz already exists; not overwritten
gzip: /var/log/tomcat8/app2/app2.log.gz already exists; not overwritten
gzip: /var/log/tomcat8/app3/app3.log.gz already exists; not overwritten
gzip: /var/log/tomcat8/app4/app4.log.gz already exists; not overwritten

I found a similar issue as discussed in Tomcat7 logrotate: superx_default_xml.log.gz already exists however an answer was never provided.

Although search for an answer I can't seem to find a solution for this problem and was hoping if someone here could point me in the right directlion.

We are running our Tomcat 8 servers on Tomcat8 servers on Ubuntu 16.04.1 LTS.

Kind Regards.


回答1:


- find /var/log/$NAME/ -name \*.$LOGEXT -daystart -mtime +0 -print0 \ + find /var/log/$NAME/ -name \*[0-9].$LOGEXT -daystart -mtime +0 -print0 \

log4j adds date suffix to log files names on rotation, so there must be a digit there so just add this digit to glob in /etc/cron.daily/tomcat8




回答2:


My 2cents solution:

Add the following line in /etc/default/tomcat8

LOGEXT="20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].log log.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9] txt"

This will select, for compression and purging, files like

/var/log/tomcat8/localhost.2019-09-09.log
/var/log/tomcat8/app1/app1.log.2019-09-09
/var/log/tomcat8/localhost_access_log.2019-09-09.txt

and leave alone app1.log files, which presumably will be renamed by a log4j appender.

Thus /etc/cron.daily/tomcat8 does not need to be changed.

Works with the tomcat8 of the Debian 9 (stretch) distribution. YMMV.



来源:https://stackoverflow.com/questions/39788775/tomcat8-on-ubuntu-log-gz-already-exists-not-overwritten

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!