zoukankan      html  css  js  c++  java
  • "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




  • 相关阅读:
    微信小程序订阅消息
    自动生成小学四则运算题目
    个人项目作业
    自我介绍+软工5问
    软件工程之获小黄衫感言
    2020软件工程个人作业06——软件工程实践总结作业
    2020软件工程作业05
    2020软件工程作业00——问题清单
    2020软件工程作业04
    2020软件工程作业03
  • 原文地址:https://www.cnblogs.com/softidea/p/4152397.html
Copyright © 2011-2022 走看看