tomcat默认日志优化处理
文章发布较早,内容可能过时,阅读注意甄别。
正常情况下,tomcat 默认的程序会输出一大堆的日志,而这些日志,对日常运维来说,帮助并不大,反而徒增不少的烦人文件。
这些都可以通过配置给优化掉。
# 1,针对 logging.properties。
修改conf/logging.properties
日志配置文件可以屏蔽掉部分的日志信息。
将 level 级别设置成 WARNING 就可以大量减少日志的输出,当然也可以设置成 OFF,直接禁用掉。
可以直接用下边的内容替换掉原来的文件。如果也是tomcat8的话。
1
[root@node1 tomcat]$cat conf/logging.properties
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.AsyncFileHandler.level = OFF
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
java.util.logging.ConsoleHandler.level = OFF
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = OFF
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = OFF
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = OFF
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 2,关闭 localhost_access_log 日志。
修改在 tomcat 的安装目录 conf 文件夹下 server.xml 里配置,将 AccessLogValve 注释掉。
<!-- Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" / -->
1
2
3
2
3
一般这段代码的位置就在配置的底部,注释掉。
# 3,管理 catalina.out。
这个文件是 tomcat 的启动日志,很多时候可以帮助我们运维,可以留下来。
如果需要关闭,则可以设置bin/catalina.sh
文件:
搜索:
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi
1
2
3
2
3
可以更改后边的输出路径为/dev/null
,让启动日志从此无影无踪。
但是一般不建议关闭这条日志输出,而时间长了之后,这个文件又会非常大,可以通过定时任务的策略进行定期清空处理:
crontab -e
#clean the log
0 */4 * * * echo a > /usr/local/tomcat/logs/catalina.out
1
2
3
4
2
3
4
上次更新: 2024/07/04, 22:40:37