Tomcat:修改日志输出位置

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: Tomcat:修改日志输出位置

认识Tomcat的日志:catalina.out、localhost、manager、localhost_access_log

参考:https://blog.csdn.net/fly910905/article/details/78463909


修改日志输出位置

修改localhost 、catalina 、manager 、host-manager 输出位置

编辑Tomcat下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.
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.AsyncFileHandler.level = FINE
#1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.directory = /data01/组织名/tomcat-log/项目名/tomcat/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
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.directory = /data01/组织名/tomcat-log/项目名/tomcat/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8
3manager.org.apache.juli.AsyncFileHandler.level = FINE
#3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.directory =/data01/组织名/tomcat-log/项目名/tomcat/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
#4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.directory = /data01/组织名/tomcat-log/项目名/tomcat/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
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.encoding = UTF-8
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
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
# To see debug messages for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE
# To see debug messages for WebSocket handling, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE


修改localhost 、catalina 、manager 、host-manager 输出位置

编辑Tomcat下conf/server.xml文件


修改catalina.out的输出目录

编辑Tomcat下bin/catalina.sh文件

修改

if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi

if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT=/data01/组织名/tomcat-log/项目名/tomcat/logs/catalina.%Y-%m-%d.out
fi


运行效果

 


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
7月前
|
应用服务中间件
Tomcat日志中文乱码
Tomcat日志中文乱码
|
8月前
|
应用服务中间件
Tomcat日志中文乱码
通过以上步骤,你可以在Tomcat日志中解决中文乱码问题,确保日志以UTF-8编码输出。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
78 4
|
8月前
|
Java 应用服务中间件
解决IDEA tomcat控制台只有server日志
请注意,确保在调试或开发阶段使用更详细的日志级别(如 `DEBUG`或 `TRACE`),但在生产环境中应将其设置为更高的级别以减少日志量。
235 0
|
8月前
|
Oracle Java 关系型数据库
淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.鏈嶅姟鍣ㄧ増鏈�: Apache Tomcat/8.5.
淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.鏈嶅姟鍣ㄧ増鏈�: Apache Tomcat/8.5.
122 1
|
应用服务中间件
Tomcat启动时日志报 dcom.sun.manager.jmxremote 异常导致无法正常启动使用
Tomcat启动时日志报 dcom.sun.manager.jmxremote 异常导致无法正常启动使用
229 0
|
应用服务中间件 Linux
Linux不重启Tomcat清空catalina.out日志的几种方法
Linux不重启Tomcat清空catalina.out日志的几种方法
539 0
|
Unix 应用服务中间件 Linux
Tomcat清理日志文件无法立即释放磁盘空间
Tomcat清理日志文件无法立即释放磁盘空间
154 0
|
移动开发 应用服务中间件 Linux
linux启动tomcat并查看启动日志
linux启动tomcat并查看启动日志
1104 0
|
监控 应用服务中间件 Linux
linux中用tailf实时观看tomcat日志
linux中用tailf实时观看tomcat日志
180 0
|
监控 Java 应用服务中间件
简单看看就会的tomcat全家桶(部署-多实例-监控-远程上传-日志-优化等)(下)
简单看看就会的tomcat全家桶(部署-多实例-监控-远程上传-日志-优化等)(下)
170 0

热门文章

最新文章