原文链接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
来自 https://blog.csdn.net/ystyaoshengting/article/details/82969371
【Tomcat】tomcat logs 目录下各日志文件的含义
十二月 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
[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.
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
### 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
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; } }
<!-- 全局结果集,将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
来自 https://www.cnblogs.com/qlqwjy/p/8036091.html
linux中tomcat修改错误日志路径
log4j.rootCategory=WARN , R, D,stdout # Console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.R.Threshold = INFO log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n # R log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=../logs/log.log #将log日志记录到tomcat下的logs文件夹 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.Threshold = DEBUG log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p ~ %m ~ %l ~ %c ~ %r%n # D log4j.appender.D=org.apache.log4j.DailyRollingFileAppender log4j.appender.D.File=../logs/error.log #将错误日志记录到tomcat下的logs文件夹 log4j.appender.D.layout=org.apache.log4j.PatternLayout log4j.appender.D.Threshold = ERROR #日志级别 log4j.appender.D.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %-5p ~ %m ~ %l ~ %c ~ %r%n