ERROR StatusLogger Log4j2 could not find a logging implementation.

今天在学习structs2  2.5.5的版本的时候碰到2个问题。第一个网上下的包里面差log4j-core这个包。

虽然程序可以运行,但控制台会报这个错误。

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

在添加了这个包后在再次运行程序。

控制台提示

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

找不到log4j2的配置文件

网上google之。找到文档。原来只要在classpath下的目录添加一个log4j2.xml。就可以了

 1 <?xml version="1.0" encoding="UTF-8"?>  
 2 <Configuration status="warn">  
 3             <Appenders>  
 4                         <Console name="Console" target="SYSTEM_OUT">  
 5                                     <PatternLayout pattern="[%-5p] %d %c - %m%n" />  
 6                         </Console>  
 7                         <File name="File" fileName="dist/my.log">  
 8                                     <PatternLayout pattern="%m%n" />  
 9                         </File>  
10             </Appenders>  
11   
12             <Loggers>  
13                         <Logger name="mh.sample2.Log4jTest2" level="INFO">  
14                                     <AppenderRef ref="File" />  
15                         </Logger>  
16                         <Root level="INFO">  
17                                     <AppenderRef ref="Console" />  
18                         </Root>  
19             </Loggers>  
20 </Configuration>

这里为什么这样配置就不说了,可以去查阅log4j2的文档。

在次运行程序,控制台没有错误提示了

原文:http://xtceetg.blog.51cto.com/5086648/1877001

原文地址:https://www.cnblogs.com/seven1314pp/p/7765123.html