标签:
《Tomcat日志系统详解》
综合:Tomcat下相关的日志文件
Cataline引擎的日志文件,文件名catalina.日期.log
Tomcat下内部代码丢出的日志,文件名localhost.日期.log(jsp页面内部错误的异常,org.apache.jasper.runtime.HttpJspBase.service类丢出的,日志信息就在该文件!)
Tomcat下默认manager应用日志,文件名manager.日期.log
控制台输出的日志,Linux下默认重定向到catalina.out
Access日志(Servlet.xml配置)
应用程序通过log4j.properties:${catalina.base}/logs/probe.log重定向过来的日志
JULI:org.apache.juli.FileHandler对应的日志文件名:{prefix}.{date}.{suffix} 默认juli.日期.log
Tomcat下Web应用程序可以使用如下3种日志:
使用JDK提供的日志java.util.logging.
使用Java Servlets规范中定义的日志javax.servlet.ServletContext.log(...)
使用其他日志框架,如log4j
不同Web应用程序下使用的Servlet日志(或者日志框架提供的日志)是相互独立的(这与Tomcat的class loader有关,参考Class Loader HOW-TO
)。如果Web应用程序使用的是java.util.logging日志,那么它们并不相互独立,这是因为java.util.logging是由JAVA系统中的Bootstrap ClassLoader来加载的,因此它在各Web应用程序之间是共享的!
Tomcat使用的日志配置文件:$CATALINA_BASE/conf/logging.properties
Tomcat日志管理类默认使用的是JULI:LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
Java的stdout and stderr会被重定向到$CATALINA_BASE/logs/catalina.out,同时:下面2种类型的错误信息,也会被记录在这里
Uncaught exceptions printed by java.lang.ThreadGroup.uncaughtException(..
Thread dumps, if you requested them via a system signal
Access访问日志:它与一般的日志有关系但不太一样,它在Servlet.xml中的Context或者 Host或者Engine中配置。在上述的配置节中增加下述的Value就行,具体参考:The Valve Component
Xml代码
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".logs" pattern="common" resolveHosts="false"/>
Tomcat默认使用JULI日志系统(可以参考官网文档修改成使用log4j),它是对默认的JDK日志java.util.logging进行一定的封装,和标准JDK日志支持相同的配置。最大的不同是针对不同的classloader,可以使用不同的配置文件,使得tomcat下不同的Web应用程序可以使用各自独立的日志文件。也就是说,Tomcat下的默认日志有如下2个层次:
全局配置文件. That is usually done in the ${catalina.base}/conf/logging.properties file. The file is specified by the java.util.logging.config.file System property which is set by the startup scripts. If it is not readable or is not configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE.
Web应用程序中使用WEB-INF/classes/logging.properties
默认的JRE中的logging.properties会把日志输出到System.err(ConsoleHandler)中,而默认的Tomcat下的配置文件conf/logging.properties会增加多个FileHandlers把日志输出到不同的文件。
JULI日志的扩展配置:
前缀,使得对于一个class可以由多个handler进行处理:A prefix may be added to handler names, so that multiple handlers of a single class may be instantiated. A prefix is a String which starts with a digit, and ends with ‘.‘. For example, 22foobar. is a valid prefix.
引用系统变量,比如使用${catalina.base}/logs/prj.log直接把项目prj的日志定位到tomcat下logs目录:System property replacement is performed for property values which contain ${systemPropertyName}.
As in Java 6.0, loggers can define a list of handlers using the loggerName.handlers property.
By default, loggers will not delegate to their parent if they have associated handlers. This may be changed per logger using the loggerName.useParentHandlers property, which accepts a boolean value.
根looger:The root logger can define its set of handlers using the .handlers property.
Tomcat JULI日志格式:使用Engine,Host, Context来定义日志,Engine一般是Catalina。
org.apache.catalina.core.ContainerBase.[${engine}].[${host}].[${context}]
Tomcat下默认的的配置文件${catalina.base}/conf/logging.properties:
Java代码
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.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.
############################################################
# Cataline引擎的日志文件,文件名catalina.日期.log
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
# Tomcat下内部代码丢出的日志,文件名localhost.日期.log
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
# Tomcat下默认manager应用日志,文件名manager.日期.log
3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.prefix = manager.
# 控制台输出的日志,Linux下默认重定向到catalina.out
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
# Wen应用程序/manager的日志
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler
# Wen应用程序/host-manager的日志
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
# For example, set the com.xyz.foo logger to only log SEVERE
# messages:
#org.apache.catalina.startup.ContextConfig.level = FINE
#org.apache.catalina.startup.HostConfig.level = FINE
#org.apache.catalina.session.ManagerBase.level = FINE
#org.apache.catalina.core.AprLifecycleListener.level=FINE
标签:
原文地址:http://www.cnblogs.com/dazhaxie/p/4846411.html