log4j:WARN No appenders could be found for logger in web.xml

后端 未结 12 1881
温柔的废话
温柔的废话 2020-11-30 21:54

I already put the log4jConfigLocation in web.xml, but I still get the following warning:

log4j:WARN No appenders cou         


        
相关标签:
12条回答
  • 2020-11-30 22:26

    Add log4jExposeWebAppRoot -> false in your web.xml. It works with me :)

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>path/log4j.properties</param-value>
    </context-param>
    <context-param>
        <param-name>log4jExposeWebAppRoot</param-name>
        <param-value>false</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    
    0 讨论(0)
  • 2020-11-30 22:28

    You'll see this warning if log4j can't find a file "log4j.properties" or "log4j.xml" anywhere.

    0 讨论(0)
  • 2020-11-30 22:28

    I had the same problem . Same configuration settings and same warning message . What worked for me was : Changing the order of the entries .

    • I put the entries for the log configuration [ the context param and the listener ] on the top of the file [ before the entry for the applicationContext.xml ] and it worked .

    The Order matters , i guess .

    0 讨论(0)
  • 2020-11-30 22:30

    I had log4j.properties in the correct place in the classpath and still got this warning with anything that used it directly. Code using log4j through commons-logging seemed to be fine for some reason.

    If you have:

    log4j.rootLogger=WARN
    

    Change it to:

    log4j.rootLogger=WARN, console
    log4j.appender.console=org.apache.log4j.ConsoleAppender
    log4j.appender.console.layout=org.apache.log4j.PatternLayout
    log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n
    

    According to http://logging.apache.org/log4j/1.2/manual.html:

    The root logger is anonymous but can be accessed with the Logger.getRootLogger() method. There is no default appender attached to root.

    What this means is that you need to specify some appender, any appender, to the root logger to get logging to happen.

    Adding that console appender to the rootLogger gets this complaint to disappear.

    0 讨论(0)
  • 2020-11-30 22:31

    If that's the entire log4j.properties file it looks like you're never actually creating a logger. You need a line like:

    log4j.rootLogger=debug,A1
    
    0 讨论(0)
  • 2020-11-30 22:31

    Or, you could be doing what I did and define the logger before the log configuration file has been loaded. This would be as they say: "Putting the cart before the horse."

    In the code:

    public static Logger logger = Logger.getLogger("RbReport");
    

    ... later on

    PropertyConfigurator.configure(l4j);
    logger = Logger.getLogger("RbReport");
    

    Fix was to initialize the logger after the configuration was loaded.

    For the geeks it was "Putting Descarte b4 d horse".

    0 讨论(0)
提交回复
热议问题