综合:Tomcat下相关的日志文件
catalina引擎的日志文件,文件名: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
<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把日志输出到不同的文件。
Tomcat JULI日志格式:使用Engine,Host, Context来定义日志,Engine一般是Catalina。
org.apache.catalina.core.ContainerBase.[${engine}].[${host}].[${context}]
Tomcat下默认的的配置文件
${catalina.base}/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.prefix = catalina. 2localhost.org.apache.juli.AsyncFileHandler.level = FINE 2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost. 3manager.org.apache.juli.AsyncFileHandler.level = FINE 3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.AsyncFileHandler.prefix = manager. 4host-manager.org.apache.juli.AsyncFileHandler.level = FINE 4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager. java.util.logging.ConsoleHandler.level = FINE 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 = 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
参考:
http://blog.csdn.net/xysoul/article/details/50347285