从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.的更多相关文章

  1. ERROR StatusLogger Log4j2 could not find a logging implementation.

    今天在学习structs2  2.5.5的版本的时候碰到2个问题.第一个网上下的包里面差log4j-core这个包. 虽然程序可以运行,但控制台会报这个错误. ERROR StatusLogger L ...

  2. 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 ...

  3. 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 ...

  4. 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  版本后, ...

  5. 关于打包后提示无法连接到mongodb的情况

    昨天晚上要和前端联调. 打完jar包后发现无法连接到测试环境的数据库. 就很尴尬,最后发现问题在于mongodb的URI写错了: 正确的URI格式:mongodb://url:port/dbName ...

  6. 测试中出现ERROR StatusLogger No log4j2 configuration file

    概述 在hibernate框架搭建完成用log4j2进行测试时,总是出现ERROR StatusLogger No log4j2 configuration file found. Using def ...

  7. Log4j2报错ERROR StatusLogger Unrecognized format specifier

    问题 使用maven-shade-plugin或者maven-assembly-plugin插件把项目打成一个可执行JAR包时,如果你引入了log4j2会出现如下问题: ERROR StatusLog ...

  8. 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 ...

  9. .net core 发布后提示Start error

    纪录篇: 发布Core版本的项目后一直提示error,通过网络查询资料后确认梳理问题的逻辑   1.验证环境是否支持,开发环境及server环境        参考:https://docs.micr ...

随机推荐

  1. 仿联想商城laravel实战---2、后端页面搭建(验证码如何在页面中使用)

    仿联想商城laravel实战---2.后端页面搭建(验证码如何在页面中使用) 一.总结 一句话总结: 放在img里面,img的src就是生产验证码的控制器路径: img src="/admi ...

  2. C#中string.Empty、""和null 之间的区别

    1.C#中string.Empty.""和null 之间的区别 (http://blog.csdn.net/henulwj/article/details/7830615)

  3. bzoj 4103: 异或运算 可持久化Trie

    题目大意: 给定长度为n的数列X={x1,x2,...,xn}和长度为m的数列Y={y1,y2,...,ym},令矩阵A中第i行第j列的值\(A_{ij} = x_i \text{ xor } y_j ...

  4. JavaScript下的进制转换

    JavaScript下的进制转换 //十进制转其他进制 var num = 99; console.log('十进制: ', num); console.log('八进制:', (num).toStr ...

  5. 用Fiddler2来监听HTTP(记:用skydrive sdk访问时,出错后用Fidder抓包分析)

    最近在写一个关于如何上传文件到skydrive的demo, 用REST上传失败. 安装Telerik的Fiddler后, 可以监听http或者https通信, 然后可以在软件中看到返回的json数据或 ...

  6. 文件上传框的美化+预览+ajax

    1.文件上传基本写法: <input type="file" name="" id="" value="" /&g ...

  7. Azure上部署Barracuda WAF集群 --- 1

    公有云上的第一层防护,一般要采用Proxy模式的安全设备. 梭子鱼的WAF是最早支持Azure China公有云的安全设备. 本文记录了在Azure上安装部署Barracuda的过程.下面就是安装部署 ...

  8. SQL Server BCP 资料导入导出

    SQL Server BCP 导入导出使用 Bcp 导出导入数据高效,比使用SQL Server Management Stdio 提供的数据库导出导入要高效因为sql server 也没有提供提供类 ...

  9. java中的接口和抽象类的区别

    1.接口从用户的角度(使用实现的代码)看问题. 2.接口由编译器强制的一个模块间协作的合约. 3.无成员变量. 4.成员函数只能声明不能实现,(jdk1.8中的default 方法可以有方法体). 接 ...

  10. linux日常管理-rsync后台服务方式-2

    把本地的数据拷贝到远程 这里是个错误,read only.只允许读,不允许写. 改一下远程机器的配置文件 把read only改为no 拷贝到远程成功 tree一下远程机器的目录 ////////// ...