使用Log4j2,打包后提示ERROR StatusLogger Log4j2 could not find a logging implementation.
2017-03-14 14:21
806 查看
从Log4j切换到Log4j2,没有打包之前日志输出正常,但是打包后总是提示下面内容:
错误一:
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 LogManager returned an instance of org.apache.logging.log4j.simple.SimpleLoggerContextFactory which does not implement org.apache.logging.log4j.core.impl.Log4jContextFactory. Unable to initialize Log4j.
被这个问题折腾了一天多,总算是找到一个解决办法,在这里记录一下。
错误一:
网上有人说是没有导入log4j-core,但是导入后还是出现这个错误。
有人说log4j2有个加载配置文件的顺序(https://logging.apache.org/log4j/2.x/manual/configuration.html),所以试了各种名字,还是失败。
这里还尝试了添加启动参数(-Dlog4j.configurationFile=log4j2.xml),以及在src下添加log4j2.component.properties文件(内容:log4j.configurationFile=log4j2.xml),结果同样失败。
错误二:
这个问题在网上没有多少可以参考的信息,但是在解决错误一时,看到有log4j2.component.properties这个配置文件,所以抱着试试的态度,到官方上查了一下,有这样的内容:
https://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties
然后果断在src下添加log4j2.component.properties文件(内容:log4j2.loggerContextFactory=org.apache.logging.log4j.core.impl.Log4jContextFactory),接着打包运行,日志正常输出了。鼓掌!!!
这里还发现了一个比较好用的配置参数,就是上面提到的log4j.configurationFile。
尝试后发现:
1.如果不配或者只配置名字(log4j2.xml),就会在jar包内查找log4j2.xml
2.如果配置jar外的绝对路径,就会在jar包外查找log4j2.xml。这个好处就是配置改动后,就不用重新打包了。
log4j2.component.properties:
错误一:
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 LogManager returned an instance of org.apache.logging.log4j.simple.SimpleLoggerContextFactory which does not implement org.apache.logging.log4j.core.impl.Log4jContextFactory. Unable to initialize Log4j.
被这个问题折腾了一天多,总算是找到一个解决办法,在这里记录一下。
错误一:
网上有人说是没有导入log4j-core,但是导入后还是出现这个错误。
有人说log4j2有个加载配置文件的顺序(https://logging.apache.org/log4j/2.x/manual/configuration.html),所以试了各种名字,还是失败。
这里还尝试了添加启动参数(-Dlog4j.configurationFile=log4j2.xml),以及在src下添加log4j2.component.properties文件(内容:log4j.configurationFile=log4j2.xml),结果同样失败。
错误二:
这个问题在网上没有多少可以参考的信息,但是在解决错误一时,看到有log4j2.component.properties这个配置文件,所以抱着试试的态度,到官方上查了一下,有这样的内容:
https://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties
然后果断在src下添加log4j2.component.properties文件(内容:log4j2.loggerContextFactory=org.apache.logging.log4j.core.impl.Log4jContextFactory),接着打包运行,日志正常输出了。鼓掌!!!
这里还发现了一个比较好用的配置参数,就是上面提到的log4j.configurationFile。
尝试后发现:
1.如果不配或者只配置名字(log4j2.xml),就会在jar包内查找log4j2.xml
2.如果配置jar外的绝对路径,就会在jar包外查找log4j2.xml。这个好处就是配置改动后,就不用重新打包了。
log4j2.component.properties:
1 log4j2.loggerContextFactory=org.apache.logging.log4j.core.impl.Log4jContextFactory 2 log4j.configurationFile=/home/*****/*****/config/log4j2.xml 3 #log4j.configurationFile=log4j2.xml
相关文章推荐
- ERROR StatusLogger Log4j2 could not find a logging implementation.
- ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the clas
- Log4j2 could not find a logging implementation
- Struts2 ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging
- asm.jar使用不了,Error:Could not find adb, please install Android SDK and set path to adb
- maven项目图标带红色感叹号(红灯、红点、红线)且保存时无法自动编译(无法生成class文件,提示Error: Could not find or load main class,或者代码改动后输出
- ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only err
- php使用pdo操作数据库时出现ERROR:could not find driver的解决方法
- (Error)Error:(28, 0) Could not find method implementation() for arguments [com.android.support:appco
- 在mahout安装目录下输入mahout 提示 ERROR: Could not find mahout-examples-*.job
- 编译android内核和文件系统,已经安装jdk,提示build/core/config.mk:268: *** Error: could not find jdk tools.jar
- 使用drozer连接时提示:Could not find java. Please ensure that it is installed and on your path
- ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only err
- ionic2打包安卓报错:Error: Could not find an installed version of Gradle either in Android Studio
- asm.jar使用不了,Error:Could not find adb, please install Android SDK and set path to adb
- ionic2打包生成APK报错 Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. Looked here: D:\Android\SDK\tools\templates\gradle\wrapper
- 关于TOMCAT 运行提示 log4j:ERROR Could not find value for key log4j.appender.CONSOLE
- 编译android内核和文件系统,已经安装jdk,提示build/core/config.mk:268: *** Error: could not find jdk tools.jar
- maven使用命令创建项目失败[ERROR] Could not find goal 'create' in plugin org.apache.maven.plugins:maven-archety
- 编译android内核和文件系统,已经安装jdk,提示build/core/config.mk:268: *** Error: could not find jdk tools.jar