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

后端 未结 12 1880
温柔的废话
温柔的废话 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:11

    OK, I see a lot of answer and some very correct. However, none fixed my problem. The problem in my case was the UNIX filesystem permissions had the log4j.properties file I was editing on the server as owned by root. and readable by only root. However, the web application I was deploying was to tomcat couldn't read the file as tomcat runs as user tomcat on Linux systems by default. Hope this helps. so the solution was typing 'chown tomcat:tomcat log4j.properties' in the directory where the log4j.properties file resides.

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

    If you want to configure for the standalone log4j applications, you can use the BasicConfigurator. This solution won't be good for the web applications like Spring environment.

    You need to write-

    BasicConfigurator.configure();
    

    or

    ServletContext sc = config.getServletContext();
    String log4jLocation = config.getInitParameter("log4j-properties-location");
    String webAppPath = sc.getRealPath("/");
    String log4jProp = webAppPath + log4jLocation;
    PropertyConfigurator.configure(log4jProp);
    
    0 讨论(0)
  • 2020-11-30 22:14

    In my case the solution was easy. You don't need to declare anything in your web.xml.

    Because your project is a web application, the config file should be on WEB-INF/classes after deployment. I advise you to create a Java resource folder (src/main/resources) to do that (best pratice). Another approach is to put the config file in your src/main/java.

    Beware with the configuration file name. If you are using XML, the file name is log4j.xml, otherwise log4j.properties.

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

    You may get this error when your log4j.properties are not present in the classpath.

    This means you have to move the log4j.properties into the src folder and set the output to the bin folder so that at run time log4j.properties will read from the bin folder and your error will be resolved easily.

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

    Put these lines in the beginning of web.xml:

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:/main/resources/log4j.xml</param-value>
    </context-param> 
    
    0 讨论(0)
  • 2020-11-30 22:25

    If still help, verify the name of archive, it must be exact "log4j.properties" or "log4j.xml" (case sensitive), and follow the hint by "Alain O'Dea". I was geting the same error, but after make these changes everthing works fine. just like a charm :-). hope this helps.

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