【Tomcat】tomcat logs 目录下各日志文件的含义

 
  tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份。可以帮助我们更好的找出错误。
 
一、  认识各种目录的作用及记录的信息
目录
 
1.catalina.日期.log
  这个主要是记录tomcat启动时候的信息,类似于我们在eclipse中启动服务的时候在控制台看到的信息。在里面可以看到启动的JVM参数以及操作系统等日志信息。如果没有使用log4j等日志机制,系统的的错误信息与打印语句也在这个日志文件中记录。(linux下所有的日志都在catalina.out中)
例如:
十二月 14, 2017 11:04:27 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
十二月 14, 2017 11:04:27 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
十二月 14, 2017 11:04:27 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version:        Apache Tomcat/7.0.72
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built:          Sep 14 2016 12:12:26 UTC
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number:         7.0.72.0
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 8
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version:            6.2
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture:          amd64
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home:             C:\Program Files\Java2\jdk1.7.0_80\jre
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version:           1.7.0_80-b15
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor:            Oracle Corporation
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         E:\tomcat\apache-tomcat-7.0.72
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         E:\tomcat\apache-tomcat-7.0.72
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=E:\tomcat\apache-tomcat-7.0.72
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=E:\tomcat\apache-tomcat-7.0.72
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=E:\tomcat\apache-tomcat-7.0.72\endorsed
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.io.tmpdir=E:\tomcat\apache-tomcat-7.0.72\temp
十二月 14, 2017 11:04:27 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
十二月 14, 2017 11:04:28 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.util.logging.config.file=E:\tomcat\apache-tomcat-7.0.72\conf\logging.properties
十二月 14, 2017 11:04:28 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: exit
十二月 14, 2017 11:04:28 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Xms3500m
十二月 14, 2017 11:04:28 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Xmx3500m
十二月 14, 2017 11:04:28 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Xss1024k
十二月 14, 2017 11:04:28 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: Loaded APR based Apache Tomcat Native library 1.2.8 using APR version 1.5.2.
十二月 14, 2017 11:04:28 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
十二月 14, 2017 11:04:29 下午 org.apache.catalina.core.AprLifecycleListener initializeSSL
信息: OpenSSL successfully initialized (OpenSSL 1.0.2h  3 May 2016)
十二月 14, 2017 11:04:29 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-80"]
十二月 14, 2017 11:04:29 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
十二月 14, 2017 11:04:29 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-apr-8009"]
十二月 14, 2017 11:04:29 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 5531 ms
十二月 14, 2017 11:04:29 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
十二月 14, 2017 11:04:30 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.72
十二月 14, 2017 11:04:31 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [367] milliseconds.
十二月 14, 2017 11:04:32 下午 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor E:\tomcat\apache-tomcat-7.0.72\conf\Catalina\localhost\Exam.xml
十二月 14, 2017 11:04:32 下午 org.apache.catalina.startup.SetContextPropertiesRule begin
警告: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Exam' did not find a matching property.
十二月 14, 2017 11:04:42 下午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
十二月 14, 2017 11:05:01 下午 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deployment of configuration descriptor E:\tomcat\apache-tomcat-7.0.72\conf\Catalina\localhost\Exam.xml has finished in 29,545 ms
十二月 14, 2017 11:05:01 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\docs
十二月 14, 2017 11:05:02 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\docs has finished in 227 ms
十二月 14, 2017 11:05:02 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\examples
十二月 14, 2017 11:05:02 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\examples has finished in 659 ms
十二月 14, 2017 11:05:02 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\host-manager
十二月 14, 2017 11:05:02 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\host-manager has finished in 192 ms
十二月 14, 2017 11:05:02 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\manager
十二月 14, 2017 11:05:03 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\manager has finished in 134 ms
十二月 14, 2017 11:05:03 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\ROOT
十二月 14, 2017 11:05:03 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory E:\tomcat\apache-tomcat-7.0.72\webapps\ROOT has finished in 106 ms
十二月 14, 2017 11:05:03 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-80"]
十二月 14, 2017 11:05:03 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
十二月 14, 2017 11:05:03 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 33450 ms

 

 
2.commons-daemon.日期.log
  这个日期放的估计是利用服务方式启动tomcat作为守护进程的日志记录,因为我的tomcat启动方式是以服务的方式启动的,索引产生这个日志文件记录了服务的启动状态。
例如:
[2017-12-16 15:45:49] [info]  [1706572] Commons Daemon procrun (1.0.15.0 64-bit) started
[2017-12-16 15:45:49] [info]  [1706572] Running 'Tomcat7' Service...
[2017-12-16 15:45:49] [info]  [1706632] Starting service...
[2017-12-16 15:45:51] [info]  [1706632] Service started in 1617 ms.
[2017-12-16 15:50:57] [info]  [1716024] Stopping service...
[2017-12-16 15:50:58] [info]  [1716024] Service stop thread completed.
[2017-12-16 15:50:59] [info]  [1706572] Run service finished.
[2017-12-16 15:50:59] [info]  [1706572] Commons Daemon procrun finished
[2017-12-16 15:51:21] [info]  [1711056] Commons Daemon procrun (1.0.15.0 64-bit) started
[2017-12-16 15:51:22] [info]  [1711056] Running 'Tomcat7' Service...
[2017-12-16 15:51:22] [info]  [1716072] Starting service...
[2017-12-16 15:51:23] [info]  [1716072] Service started in 1511 ms.

 

 

3.host-manager.日期.log
  这个估计是放tomcat的自带的manager项目的日志信息的,也没有看到有什么重要的日志信息
4.localhost.日期.log
  这个类似于第一种日志,可是信息没有第一种全
5.localhost_access_log.日期.txt
  这个是存放访问tomcat的请求的所有地址以及请求的路径、时间,请求协议以及返回码等信息(重要)
例如:
0:0:0:0:0:0:0:1 - - [14/Dec/2017:23:24:03 +0800] "GET /Exam/image/newsLogo.jpg HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [14/Dec/2017:23:24:06 +0800] "POST /Exam/train_findStudyTraincontentByFy.action HTTP/1.1" 200 25
0:0:0:0:0:0:0:1 - - [14/Dec/2017:23:24:06 +0800] "POST /Exam/newsIP_getTypeNews.action HTTP/1.1" 200 258
0:0:0:0:0:0:0:1 - - [14/Dec/2017:23:24:06 +0800] "POST /Exam/newsIP_getTypeNews.action HTTP/1.1" 200 2338

 

6.manager.日志.log
  这个估计也是manager项目专有的日志文件,看不出有什么重要的信息
7.tomcat7-stderr.日期.log  
  这个是log4j的错误日志,因此在程序中要合理的捕捉异常。
8.tomcat7-stdout.日期.log  (类似于eclipse的控制台的信息)
  这个是程序中的System语句打印的日志(包括系统抛出的异常),也终于明白了为什么一再强调不能用打印语句进行系统调试
 
针对上面7,8做的测试:
log4j.properties
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###
#\u5728\u5F00\u53D1\u9636\u6BB5\u65E5\u5FD7\u7EA7\u522B\u4F7F\u7528debug
log4j.rootLogger=error, stdout
### \u5728\u65E5\u5FD7\u4E2D\u8F93\u51FAsql\u7684\u8F93\u5165\u53C2\u6570 ###
#log4j.logger.cn.xm.exam.mapper.exam=TRACE

 

TestAction.java
package cn.xm.exam.action.exam.exam;

import javax.management.RuntimeErrorException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

import jxl.common.Logger;

@Controller
@Scope("prototype")
public class TestAction extends ActionSupport {
    private Logger logger = Logger.getLogger(TestAction.class);

    public String syso() {
        System.out.println("这是打印语句");
        return SUCCESS;
    }

    public String loginfo() {
        logger.info("这是info方法的记录信息");
        return SUCCESS;
    }

    public String error() {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            logger.error("故意除零了", e);
        }
        return SUCCESS;
    }

    public String notcatch() {
        int i = 1 / 0;
        return SUCCESS;
    }

    public String runtimeexe() {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            throw new RuntimeException("除零运行时异常", e);
        }
        return SUCCESS;
    }
}

 

 

struts配置
        <!-- 全局结果集,将response转换为json传到前台 -->
        <global-results>
            <result name="success" type="json">
                <param name="root">response</param>
            </result>
        </global-results>
        <action name="test_*" class="testAction" method="{1}"></action>

 (1)访问:http://localhost/Exam/test_syso.action

 tomcat7-stdout.2017-12-14.log中多一条:     这是打印语句(每次访问日志都会记录下来)

(2)访问:http://localhost/Exam/test_loginfo.action

 tomcat7-stdout.2017-12-14.log中多出上面的日志记录信息,设置log4j的日志级别为error则不会在日志文件中记录此信息。

2017-12-16 15:51:22 Commons Daemon procrun stdout initialized
这是打印语句
这是打印语句
这是打印语句
这是打印语句
这是打印语句
这是打印语句
这是info方法的记录信息
这是info方法的记录信息

 

(3)访问:http://localhost/Exam/test_error.action

  tomcat7-stderr.2017-12-15.log会记录错误信息:

Error: 故意除零了
java.lang.ArithmeticException: / by zero
    at cn.xm.exam.action.exam.exam.TestAction.error(TestAction.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:871)
    at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1294)
    at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
    at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
    at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
    at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1370)
    at ognl.ASTMethod.getValueBody(ASTMethod.java:91)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    at ognl.SimpleNode.getValue(SimpleNode.java:258)
    at ognl.Ognl.getValue(Ognl.java:467)
    at ognl.Ognl.getValue(Ognl.java:431)
    at com.opensymphony.xwork2.ognl.OgnlUtil$3.execute(OgnlUtil.java:352)
    at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecuteMethod(OgnlUtil.java:404)
    at com.opensymphony.xwork2.ognl.OgnlUtil.callMethod(OgnlUtil.java:350)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:430)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:290)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:251)
    at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:168)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:140)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:575)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1756)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1715)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

 (4)对于未捕捉的异常也会在tomcat7-stdout.日期.log记录。也就是会在控制台的地方打印,如果未拦截会抛给用户。

 

 

 (5)访问:http://localhost/Exam/test_runtimeexe.action 

  同样会在tomcat7-stdout.日期.log记录

 

 

   总结:

    系统中不能使用System,out。。。打印的方式进行调试,这些最后都会保存到日志文件浪费内存。可以使用log4j的info进行调试,最后发布的时候将log4j的日志级别调高则不会打印在日志文件中,这也是开发的一条重要原则。

    系统中队异常要进行捕获,这样发布后可以在日志中更好的查看错误信息,同时不会把日志抛给用户。

        

 
 
 
 

二、设置日志级别以及输出位置

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.打开访问日志

编辑 ${catalina}/conf/server.xml 文件. 注 :${catalina} 是 tomcat 的安装目录

 <!--

 

 

 

pattern可以修改格式

common 的值: %h %l %u %t %r %s %b

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

posted @ 2017-12-14 09:38  QiaoZhi  阅读(95481)  评论(2编辑  收藏