日志有两种
- 访问日志
- 运行日志
访问日志
日志配置(注释即可关闭):
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
实例:
-rwxrwxr-x 1 worker worker 84813 Jan 9 13:39 localhost_access_log.2020-01-09.txt
内容:
10.200.9.86 - - [09/Jan/2020:13:38:56 +0800] "POST /provider/48/provider-detail.htm HTTP/1.1" 200 591
10.200.9.86 - - [09/Jan/2020:13:39:02 +0800] "GET /index.htm HTTP/1.1" 200 6311
10.200.9.86 - - [09/Jan/2020:13:39:02 +0800] "POST /provider/48/provider-detail.htm HTTP/1.1" 200 591
10.200.9.86 - - [09/Jan/2020:13:39:07 +0800] "GET /index.htm HTTP/1.1" 200 6311
10.200.9.86 - - [09/Jan/2020:13:39:07 +0800] "POST /provider/48/provider-detail.htm HTTP/1.1" 500 3887
10.200.9.86 - - [09/Jan/2020:13:39:10 +0800] "POST /app/list.htm HTTP/1.1" 200 1498
10.200.9.86 - - [09/Jan/2020:13:39:15 +0800] "POST /app/xxx-consumer/nodes.htm HTTP/1.1" 200 12
10.200.9.86 - - [09/Jan/2020:13:39:18 +0800] "POST /app/list.htm HTTP/1.1" 200 1442
10.200.9.86 - - [09/Jan/2020:13:39:20 +0800] "POST /dubbo-ui/loadAppsType.htm HTTP/1.1" 404 1042
10.200.9.86 - - [09/Jan/2020:13:39:20 +0800] "POST /dubbo-ui/loadServiceProtocols.htm HTTP/1.1" 404 1042
运行日志
- 运行日志分为5类:catalina 、localhost 、manager 、admin 、host-manager
- 日志的级别分为7种:SEVERE (highest value) > WARNING > INFO > CONFIG > FINE > FINER > FINEST (lowest value),除此之外,还可以使用OFF关闭相关日志,使用ALL输出所有级别的日志
- 修改 TOMCAT_HOME/conf/logging.properties 中的内容,设定某类日志的级别
# 设置 catalina 日志的级别为: FINE
catalina.org.apache.juli.FileHandler.level = FINE
# 禁用 catalina 日志的输出:
catalina.org.apache.juli.FileHandler.level = OFF
# 输出 catalina 所有的日志消息:
catalina.org.apache.juli.FileHandler.level = ALL
实际配置文件:
1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
1catalina.org.apache.juli.AsyncFileHandler.maxDays = 90 # 保留90天,可以修改
1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8
2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.maxDays = 90
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8
catalina日志太大的问题
方式1:直接关闭日志
方式二:使用logrotate
CentOS6.5后自带logrotate程序,可以解决catalina.out的日志轮转问题
cat >/etc/logrotate.d/tomcat
/usr/local/tomcat/logs/catalina.out{
copytruncate
daily
rotate 7
missingok
compress
size 16M
}
解释:
要轮转的文件
创建新的catalina.out副本,截断源catalina.out文件
每天进行catalina.out文件的轮转
至多保留7个副本
文件丢失了,轮转不报错
使用压缩
当catalina.out文件大于16MB,就轮转