Struts2-使用myeclipse时,控制台不输出timer拦截器中的信息的解决方案

学习拦截器的timer时,myeclipse始终无法在控制台打印输出timer拦截器的时间信息,此时控制台中有如下提示:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

上网查找后,发现需要导入log4j-core的jar包,但是在下载了log4j-core-2.6.1导入后仍然报上述错误,后无意间在网页中看到有人说,如果同时有log4j-core-2.9.1.jar和log4j-api-2.9.1.jar将不会出现上述问题,因此采取该方法后,果然问题得以解决。至于是因为log4j-core的jar包版本低造成的,还是没有跟log4j-api版本一致造成的,本人并未对此进行深入研究。

在解决了上述问题后,重新启动Tomcat后,控制台虽未报上述错误,但是出现了错误信息如下:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.

该错误属于,控制台默认只将错误级别为error的 错误信息进行打印,而timer拦截器中的信息因属于info级别。因此需要在src文件夹下新建一个log4j2.xml文件,将文件中的level设置为info,该配置文件的路径和内容如下:


<?xml version="1.0" encoding="UTF-8"?>  
<Configuration status="WARN">  
  <Appenders>  
    <Console name="Console" target="SYSTEM_OUT">  
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>  
    </Console>  
  </Appenders>  
  <Loggers>  
    <Root level="info">  
      <AppenderRef ref="Console"/>  
    </Root>  
  </Loggers>  
</Configuration>  
此时控制台中能正确打印出timer的信息
00:49:26.932 [http-apr-8080-exec-4] INFO  com.opensymphony.xwork2.interceptor.TimerInterceptor - Executed action [/Pages/addLeague!execute] took 341 ms.

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值