使用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 ...
随机推荐
- php数组转换成js可用的数组的两种方式
1.如果你理解JSON数据格式的话,这个问题就异常简单: <?php $a =array('1','2','3'); ?> <script language="javasc ...
- php:如何使用PHP排序, key为字母+数字的数组(多维数组)
你还在为如何使用PHP排序字母+数字的数组而烦恼吗? 今天有个小伙伴在群里问:如何将一个key为字母+数字的数组按升序排序呢? 举个例子: $test = [ 'n1' => 22423, 'n ...
- django实现用户注册、登录、退出
视图 from django.contrib import auth from django.contrib.auth.models import User from django.views.dec ...
- vi 常用编辑命令
什么是vi: vi是Linux/Unix底下最常用的文本编辑器,可以理解为和Windows下的txt一样,咱们一般操作linux服务器的时候都是没有图形化界面的, 怎么移动光标,到哪个位置,替换修改什 ...
- L99
You're not obligated to win. You're obligated to keep trying.你不一定要获胜,但你必须不断尝试.He announced an expans ...
- 多线程编程-pthread 未定义的引用
多线程编程时用到函数库 pthread.h ,但是该函数库不是linux默认的函数库,所以编译c文件时,需要在目标代码文件后加上 -lpthread参数. 1.未加上 -lpthread 编译时,报错 ...
- tensorflow训练过程中内存溢出
罪魁祸首是训练过程中给模型传值时的如下语句:
- wcf win7上使用net.tcp出现不支持协议问题解决
第一:iis绑定 net.tcp 808:* 第二:iis 应用中高级开启协议,添加net.tcp多协议逗号隔开 第三:开启各项服务 第四:执行 ServiceModReg.exe -r
- BZOJ1799 [Ahoi2009]self 同类分布[数位DP]
求出[a,b]中各位数字之和能整除原数的数的个数. 有困难的一道题.被迫看了题解:枚举每一个各位数字的和($<=162$),设计状态$f[len][sum][rest]$表示dp后面$len$位 ...
- 使用Visual Studio进行单元测试-Part5
本文主要介绍Visual Studio(2012+)单元测试框架的一些技巧: 如何模拟类的静态构造函数 如何测试某方法被调用过 如何测试某方法执行的次数 并行编程测试注意事项 一.如何模拟类的静态构造 ...