赞
踩
原文链接https://www.cnblogs.com/signheart/p/0ed0bef7dfadf59534eec76ad4607654.html
tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份
localhost.2016-07-05.txt //经常用到的文件之一 ,程序异常没有被捕获的时候抛出的地方
catalina.2016-07-05.txt //经常用到的文件之一,程序的输出,tomcat的日志输出等等
manager.2016-07-05.txt //估计是manager项目专有的
host-manager.2016-07-05.txt//估计是manager项目专有的
localhost_access_log.2016-10-01.txt //tomcat访问日志记录,需要配置
1.让所有文件都输出到同一个文件中
打开Tomcat目录conf\logging.properties,修改如下,所有日志输出到tomcat开头的文件中
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
# 1catalina.org.apache.juli.FileHandler.prefix = catalina.
1catalina.org.apache.juli.FileHandler.prefix = tomcat.
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
# 2localhost.org.apache.juli.FileHandler.prefix = localhost.
2localhost.org.apache.juli.FileHandler.prefix = tomcat.
3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
# 3manager.org.apache.juli.FileHandler.prefix = manager.
3manager.org.apache.juli.FileHandler.prefix = tomcat.
4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
# 4host-manager.org.apache.juli.FileHandler.prefix = host-manager.
4host-manager.org.apache.juli.FileHandler.prefix = tomcat.
2.打开访问日志
默认 tomcat 不记录访问日志,如下方法可以使 tomcat 记录访问日志
编辑 ${catalina}/conf/server.xml 文件. 注 :${catalina} 是 tomcat 的安装目录
把以下的注释 (<!-- -->) 去掉即可。
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
上面的pattern可以修改格式
该项值可以为: common 与 combined ,这两个预先设置好的格式对应的日志输出内容如下:
common 的值: %h %l %u %t %r %s %b
combined 的值: %h %l %u %t %r %s %b %{Referer}i %{User-Agent}i
pattern 也可以根据需要自由组合, 例如 pattern="%h %l"
对于各fields字段的含义请参照 :
http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html 中的 Access Log Valve 项
3.修改tomcat日志级别
Tomcat 日志分为下面5类:
catalina 、 localhost 、 manager 、 admin 、 host-manager
每类日志的级别分为如下 7 种:
SEVERE (highest value) > WARNING > INFO > CONFIG > FINE > FINER > FINEST (lowest value)
日志级别的设定方法
修改 conf/logging.properties 中的内容,设定某类日志的级别
示例:
设置 catalina 日志的级别为: FINE
1catalina.org.apache.juli.FileHandler.level = FINE
禁用 catalina 日志的输出:
1catalina.org.apache.juli.FileHandler.level = OFF
输出 catalina 所有的日志消息均输出:
1catalina.org.apache.juli.FileHandler.level = ALL
- #配置tomcat的日志输出方式,这里表示文件输出和控制台输出
- handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
-
- .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
-
- ############################################################
- # Handler specific properties.
- # Describes specific configuration info for Handlers.
- ############################################################
-
- #设置 catalina 日志的级别为
- 1catalina.org.apache.juli.FileHandler.level = FINE
- #日志输出目录,此设置表示tomcat日志输出到tomcat\logs目录下
- 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
- #日志输出前缀,后面跟日期信息(yyyy-MM-dd)
- 1catalina.org.apache.juli.FileHandler.prefix = catalina.
-
- 2localhost.org.apache.juli.FileHandler.level = FINE
- 2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
- 2localhost.org.apache.juli.FileHandler.prefix = localhost.
-
- 3manager.org.apache.juli.FileHandler.level = FINE
- 3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
- 3manager.org.apache.juli.FileHandler.prefix = manager.
-
- 4host-manager.org.apache.juli.FileHandler.level = FINE
- 4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
- 4host-manager.org.apache.juli.FileHandler.prefix = host-manager.
-
- #控制台日志
- java.util.logging.ConsoleHandler.level = FINE
- java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-
-
- ############################################################
- # 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.FileHandler
-
- org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
- org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler
-
- 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.FileHandler
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。