"No appenders found for logger" and "Please configure log4j properly"
Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?
This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration.
log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system. Knowing the appropriate location to place log4j.properties or log4j.xml requires understanding the search strategy of the class loader in use. log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments.
Also see FAQ: Why can't log4j find my properties in a J2EE or WAR application?.
Thread.getContextClassLoader().getResource():项目生成class文件的根目录,例如maven项目就是指target/classes/
Why can't log4j find my properties file in a J2EE or WAR application?
The short answer: the log4j classes and the properties file are not within the scope of the same classloader.
The long answer (and what to do about it): J2EE or Servlet containers utilize Java's class loading system. Sun changed the way classloading works with the release of Java 2. In Java 2, classloaders are arranged in a hierarchial parent-child relationship. When a child classloader needs to find a class or a resource, it first delegates the request to the parent.
Log4j only uses the default Class.forName() mechanism for loading classes. Resources are handled similarly. See the documentation for java.lang.ClassLoader for more details.
So, if you're having problems, try loading the class or resource yourself. If you can't find it, neither will log4j. ;)
http://logging.apache.org/log4j/1.2/faq.html#a3.5
"No appenders found for logger" and "Please configure log4j properly"的更多相关文章
- springboot+druid报错log4j:WARN No appenders could be found for logger (druid.sql.Connection). log4j:WARN Please initialize the log4j system properly.
解决方案:新建文件log4j.properties log4j.rootLogger=DEBUG, stdout log4j.appender.stdout=org.apache.log4j.Con ...
- slf4j 和 log4j合用的(Maven)配置(转)
简述:添加logger的日志输出,下面是配置信息供备忘 步骤:1. 在Maven的porn.xml 文件中添加dependency如下 <dependency> <groupId&g ...
- myecplise ssh项目配置上遇到的问题
版本:spring3.1+hib4.1+struts2.1 学习项目使用此版本运行时,总是会遇到各样的错误,在这里做一下记录. 问题1:log4j相关 spring的web项目,执行时报错: 信息: ...
- Log4j使用教程 log4:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
1.Logger类 通过Logger类的静态方法Logger.getRootLogger得到RootLogger.所有其他的loggers是通过静态方法Logger.getLogger来实例化并获取的 ...
- Logger.getLogger()和LogFactory.getLog()的区别
第一.Logger.getLogger()和LogFactory.getLog()的区别 1.Logger.getLogger()是使用log4j的方式记录日志: 2.LogFactory.getLo ...
- java出现以下警告:WARN No appenders;WARN Please initialize the log4j的处理方法
编译java或引用别的代码时出现以下警告: log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKee ...
- logger(二)logback简介及其实现原理
一.logback简介 logback是log4j创始人写的,性能比log4j要好,目前主要分为3个模块 logback-core:核心代码模块 logback-classic:log4j的一个改良版 ...
- Java日志管理:Logger.getLogger()和LogFactory.getLog()的区别(详解Log4j)
Java日志管理:Logger.getLogger()和LogFactory.getLog()的区别(详解Log4j) 博客分类: Java综合 第一.Logger.getLogger()和Log ...
- Logger.getLogger()和 LogFactory.getLog()
Logger.getLogger()和LogFactory.getLog()的区别: 1.Logger.getLogger()是使用log4j的方式记录日志:2.LogFactory.getLo ...
随机推荐
- JAVA学习第一课(初识JAVA)
PS:退ACM集训队了,自己也疯玩了两天,后天就开学了,就正式大二了,该收收心好好学习啦 ...
- gdb篇
转自:http://www.cnblogs.com/ypchenry/p/3668572.html 1.gdb的原理 熟悉linux的同学面试官会问你用过gdb么?那好用过,知道gdb是怎么工作的么? ...
- SQLHelper简单版(基础版)
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- window.showModalDialog刷新父窗口和本窗口的方法及注意
window.showModalDialog刷新父窗口和本窗口的方法及注意: 一.刷新父窗口的方法: A.使用window.returnValue给父窗口传值,然后根据值判断是否刷新. 在w ...
- struts2页面输出错误信息
<package name="user" namespace="/user" extends="struts-default"> ...
- hrtimer 高精定时器使用例子
在kernel,有个线程每个十秒往上层系统上报battery及USB的状态信息. 加入直接sleep 10 秒的话,插入USB的时候不能及时更新状态,这个时候就可以使用 hrtimer + wait ...
- win7系统无线 VirtualBox rehat 32位linux 下 host-only模式相互通信及上网 配置
虚拟机环境:virtualBox虚拟环境 redhat 32位 主机环境 : win7 无线路由 模式: host-only win7下nat模式原先的设置基于 有网线连接的情形下,在使用了无线路由之 ...
- https tomcat 证书搭建
首先生成证书说明 keytool -genkey -alias castest -keyalg RSA -keystore c:/keys/caskey 先让输入密码,密码必须记住,下面会用到 其中“ ...
- BootStrap 轮播 Carousel
参考 http://wrongwaycn.github.io/bootstrap/docs/javascript.html#collapse 同样 启动方式有2种 一种是在div的class中加 另 ...
- RFID电子标签的二次注塑封装
生活当中,RFID电子标签具有明显的优势,随着RFID电子标签成本的降低.读写距离的提高.标签存储容量增大及处理时间缩短的发展趋势,R F I D电子标签的应用将会越来越广泛. RFID电子标签的应用 ...