赞
踩
catalina.out即标准输出和标准出错,所有输出到这两个位置的都会进入catalina.out,这里包含tomcat运行自己输出的日志以及应用里向console输出的日志。默认这个日志文件是不会进行自动切割的,所以我们需要借助其他工具进行切割(注意:catalina.out文件如果过大会影响性能)
创建 logrotate 配置文件如下:
/etc/logrotate.d/tomcat
将下面的内容复制到上面的配置文件中
/var/log/tomcat/catalina.out {
copytruncate
daily
rotate 7
dateext
dateformat -%Y%m%d
compress
missingok
size 5M
}
关于上面的配置:
注意:每个配置指令都需要独占一行
编辑 crontab 配置文件:
vim /etc/crontab
将下面的内容复制到上面文件的最后一行:
## 每天0点执行
0 0 * * * root /usr/sbin/logrotate /etc/logrotate.conf
编辑 tomcat 日志配置文件:
vim ../apache-tomcat-8.5.69/conf/logging.properties
修改后配置文件如下:
1catalina.org.apache.juli.AsyncFileHandler.level = FINE 1catalina.org.apache.juli.AsyncFileHandler.formatter =java.util.logging.SimpleFormatter 1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina. 1catalina.org.apache.juli.AsyncFileHandler.maxDays = 30 1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8 2localhost.org.apache.juli.AsyncFileHandler.level = FINE 2localhost.org.apache.juli.AsyncFileHandler.formatter =java.util.logging.SimpleFormatter 2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost. 2localhost.org.apache.juli.AsyncFileHandler.maxDays = 30 2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8 3manager.org.apache.juli.AsyncFileHandler.level = FINE 3manager.org.apache.juli.AsyncFileHandler.formatter =java.util.logging.SimpleFormatter 3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.AsyncFileHandler.prefix = manager. 3manager.org.apache.juli.AsyncFileHandler.maxDays = 30 3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8 4host-manager.org.apache.juli.AsyncFileHandler.level = FINE 4host-manager.org.apache.juli.AsyncFileHandler.formatter =java.util.logging.SimpleFormatter 4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager. 4host-manager.org.apache.juli.AsyncFileHandler.maxDays = 30 4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8 java.util.logging.ConsoleHandler.level = FINE #java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter java.util.logging.ConsoleHandler.formatter =java.util.logging.SimpleFormatter java.util.logging.ConsoleHandler.encoding = UTF-8 java.util.logging.ConsoleHandler.limit = 1024000 # My special format: java.util.logging.SimpleFormatter.format = %1$tF %1$tT [%4$-7s] %5$s %n
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。