使用Log4j2,打包后提示ERROR StatusLogger Log4j2 could not find a logging implementation.
从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:
log4j2.loggerContextFactory=org.apache.logging.log4j.core.impl.Log4jContextFactory
log4j.configurationFile=/home/*****/*****/config/log4j2.xml
#log4j.configurationFile=log4j2.xml
使用Log4j2,打包后提示ERROR StatusLogger Log4j2 could not find a logging implementation.的更多相关文章
- ERROR StatusLogger Log4j2 could not find a logging implementation.
今天在学习structs2 2.5.5的版本的时候碰到2个问题.第一个网上下的包里面差log4j-core这个包. 虽然程序可以运行,但控制台会报这个错误. ERROR StatusLogger L ...
- ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath
问题: ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the ...
- ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Struts2未配置Log4j2.xml报错 Log4j2.xml中的配置 log4j的jar包:log4j-core-2.7.jar log4j2只支持xml和json两种格式的配置,所以配置log ...
- vue-cli 3.x版本执行vue ui命令后提示Error: Cannot find module ‘core-js/modules/es7.object.entries’报错的解决方法
我的方法是:npm install --save core-js(全局安装竟然不行,必须局部) vue-cli新版提供了界面化项目管理的功能,简直一万个赞! 在安装 vue-cli 3.x 版本后, ...
- 关于打包后提示无法连接到mongodb的情况
昨天晚上要和前端联调. 打完jar包后发现无法连接到测试环境的数据库. 就很尴尬,最后发现问题在于mongodb的URI写错了: 正确的URI格式:mongodb://url:port/dbName ...
- 测试中出现ERROR StatusLogger No log4j2 configuration file
概述 在hibernate框架搭建完成用log4j2进行测试时,总是出现ERROR StatusLogger No log4j2 configuration file found. Using def ...
- Log4j2报错ERROR StatusLogger Unrecognized format specifier
问题 使用maven-shade-plugin或者maven-assembly-plugin插件把项目打成一个可执行JAR包时,如果你引入了log4j2会出现如下问题: ERROR StatusLog ...
- log4j报错ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only err ...
- .net core 发布后提示Start error
纪录篇: 发布Core版本的项目后一直提示error,通过网络查询资料后确认梳理问题的逻辑 1.验证环境是否支持,开发环境及server环境 参考:https://docs.micr ...
随机推荐
- 分享知识-快乐自己:ActiveMQ 安装部署
1):下载 ActiveMQ tar 包 2):上传到 服务器中 3):解压到 指定目录中 [root@admin tools]# tar -zxvf apache-activemq-5.2.0-bi ...
- html设置编码
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- Django 文件下载功能
def file_download(request): con= MySQLdb.connect(host='192.168.xxx.xxx',user='root',passwd='xxxx',db ...
- Selenium-使用firepath获取元素的xpath
- Mybatis_学习_00_资源帖
源码:https://github.com/mybatis/mybatis-3 一.官方 (1)Mybatis官方文档中文版 (2)MyBatis 从入门到精通 书中指定的网络资源 (3)MyBat ...
- 【BZOJ 3238】差异 后缀自动机+树形DP
题意 给定字符串,令$s_i$表示第$i$位开始的后缀,求$\sum_{1\le i < j \le n} len(s_i)+len(s_j)-2\times lcp(s_i,s_j)$ 先考虑 ...
- 2018.6.21 HOLTEK HT49R70A-1 Source Code analysis
Cange note: “Reading TMR1H will latch the contents of TMR1H and TMR1L counter to the destination”? F ...
- hihocoder -1283 hiho密码(水题)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho根据最近在密码学课上学习到的知识,开发出了一款hiho密码,这款密码的秘钥是这样生成的:对于一种有N个字母的语言 ...
- codeforces 633A A. Ebony and Ivory(暴力)
A. Ebony and Ivory time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Agc017_D Game on Tree
传送门 题目大意 给定一棵树,$1$号节点为根,两个人轮流操作,每次选择一个根节点外的点,删掉它以及它的子树,不能操作者输,求两人均采用最优策略下先手胜利还是后手胜利. 题解 经典问题树上删边游戏,根 ...