"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?.

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

时间: 2024-10-14 08:05:10

"No appenders found for logger" and "Please configure log4j properly"的相关文章

myecplise struts启动问题

spring的web项目,执行时报错: 信息: Deploying web application archive SSH2.war log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider). log4j:WARN Please initialize the log4j system properly. log4j:WA

log4j:WARN No appenders could be found for logger (freemarker.cache).

为了减少控制台输出从而减少处理时间,可以设置日志级别高一点,例如设置为“ERROR” 打开类路径(就是和struts.xml文件同目录)下的log4j.properties(如果没有就新建一个),修改如下: log4j.logger.com.opensymphony.xwork2=ERROR log4j.logger.freemarker.cache=ERROR log4j.logger.freemarker.beans=ERROR log4j.logger.org.apache.struts2

Java日志管理:Logger.getLogger()和LogFactory.getLog()的区别(详解Log4j)

Java日志管理:Logger.getLogger()和LogFactory.getLog()的区别(详解Log4j) 博客分类: Java综合 第一.Logger.getLogger()和LogFactory.getLog()的区别     1.Logger.getLogger()是使用log4j的方式记录日志:  2.LogFactory.getLog()则来自apache的common-logging包. common-logging组件:         Jakarta Commons

java出现以下警告:WARN No appenders;WARN Please initialize the log4j的处理方法

编译java或引用别的代码时出现以下警告: log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 出现这个

logger(二)logback简介及其实现原理

一.logback简介 logback是log4j创始人写的,性能比log4j要好,目前主要分为3个模块 logback-core:核心代码模块 logback-classic:log4j的一个改良版本,同时实现了slf4j的接口,这样你如果之后要切换其他日志组件也是一件很容易的事 logback-access:访问模块与Servlet容器集成提供通过Http来访问日志的功能 二.logback.xml配置 <?xml version="1.0" encoding="U

log4j中Logger.getLogger与LogFactory.getLog的区别

Logger来自log4j自己的包.如果用Logger.getLogger,需要一个log4j的jar包,用此方式你只能依靠log4j; LogFactory来自common-logging包.如果用LogFactory.getLog,你可以用任何实现了通用日志接口的日志记录器替换log4j,而程序不受影响. apache的common-logging包是通用日志接口,通过这个中间层,你可以随便指定到底用哪个日志系统.增加系统的灵活性.若log4j它不存在, commons-logging 会另

Java Logger(java日志)

目录 1. 简介2. 安装3. log4j基本概念3.1. Logger3.2. Appender3.2.1. 使用ConsoleAppender3.2.2. 使用FileAppender3.2.3. 使用WriterAppender3.3. Layout3.4. 基本示例3.4.1. SimpleLayout和FileAppender3.4.2. HTMLLayout和WriterAppender3.4.3. PatternLayout和ConsoleAppender4. 使用外部配置文件5.

org.apache.log4j.Logger用法

在应用程序中添加日志记录总的来说基于三个目的 :监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作:跟踪代码运行时轨迹,作为日后审计的依据:担当集成开发环境中的调试器的作用,向文件或控制台打印代码的调试信息.最普通的做法就是在代码中嵌入许多的打印语句,这些打印语句可以输出到控制台或文件中,比较好的做法就是构造一个日志操作类 来封装此类操作,而不是让一系列的打印语句充斥了代码的主体.  (一)Log4j简介 Log4j 是 Apache 的一个开放源代码项目,通过使用 Log

log4cxx第三篇----使用多个logger

使用多个logger时,所有logger的配置写在一个配置文件里面 两个例子: 1 一个继承的例子(http://logging.apache.org/log4cxx/) // file com/foo/bar.h #include "log4cxx/logger.h" namespace com { namespace foo { class Bar { static log4cxx::LoggerPtr logger; public: void doIt(); } } } // f