博客 > 术业专攻> 网站服务> Tomcat> tomcat默认日志优化处理 2019年08月29日 11:25:52
正常情况下,tomcat默认的程序会输出一大堆的日志,而这些日志,对日常运维来说,帮助并不大,反而徒增不少的烦人文件。
这些都可以通过配置给优化掉。
修改conf/logging.properties
日志配置文件可以屏蔽掉部分的日志信息。
将level级别设置成WARNING就可以大量减少日志的输出,当然也可以设置成OFF,直接禁用掉。
可以直接用下边的内容替换掉原来的文件。如果也是tomcat8的话。
[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
修改在tomcat的安装目录conf文件夹下server.xml里配置,将AccessLogValve注释掉。
一般这段代码的位置就在配置的底部,注释掉。
这个文件是tomcat的启动日志,很多时候可以帮助我们运维,可以留下来。
如果需要关闭,则可以设置bin/catalina.sh
文件:
搜索:
if [ -z "$CATALINA_OUT" ] ; then CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out fi
可以更改后边的输出路径为/dev/null
,让启动日志从此无影无踪。
但是一般不建议关闭这条日志输出,而时间长了之后,这个文件又会非常大,可以通过定时任务的策略进行定期清空处理:
crontab -e #clean the log 0 */4 * * * echo a > /usr/local/tomcat/logs/catalina.out
© 2018 www.qingketang.net 鄂ICP备18027844号-1
武汉快勤科技有限公司 13554402156 武汉市东湖新技术开发区关山二路特一号国际企业中心6幢4层7号
扫码关注,全站教程免费播放
订单金额:
支付金额:
支付方式: