Program Tip

log4j : WARN web.xml에서 로거에 대한 추가자를 찾을 수 없습니다.

programtip 2020. 10. 12. 08:03
반응형

log4j : WARN web.xml에서 로거에 대한 추가자를 찾을 수 없습니다.


이미 log4jConfigLocation을 web.xml에 넣었지만 여전히 다음 경고가 표시됩니다.

log4j:WARN No appenders could be found for logger ⤦
    ⤥ (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.

내가 놓친 게 무엇입니까?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
    "java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.util.Log4jConfigListener
        </listener-class>
    </listener>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>suara2</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>suara2</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

이것이 전체 log4j.properties 파일이라면 실제로 로거를 생성하지 않는 것처럼 보입니다. 다음과 같은 줄이 필요합니다.

log4j.rootLogger=debug,A1

클래스 경로의 올바른 위치에 log4j.properties가 있었고 직접 사용하는 모든 경고가 계속 표시되었습니다. commons-logging을 통해 log4j를 사용하는 코드는 어떤 이유로 든 괜찮은 것 같았습니다.

당신이 가지고 있다면:

log4j.rootLogger=WARN

다음으로 변경하십시오.

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

http://logging.apache.org/log4j/1.2/manual.html 에 따르면 :

루트 로거는 익명이지만 Logger.getRootLogger () 메서드를 사용하여 액세스 할 수 있습니다. 루트에 연결된 기본 어 펜더가 없습니다.

이것이 의미하는 바는 로깅이 발생하도록 루트 로거에 일부 appender, any appender를 지정해야한다는 것입니다.

해당 콘솔 어 펜더를 rootLogger에 추가 하면이 불만이 사라집니다.


log4j.properties클래스 경로에없는 경우이 오류가 발생할 수 있습니다 .

log4j.properties,을 src 폴더로 이동하고 출력을 bin 폴더로 설정해야 런타임 log4j.properties에 bin 폴더에서 읽고 오류가 쉽게 해결 될 수 있습니다.


log4j가 "log4j.properties"또는 "log4j.xml"파일을 어디에도 찾을 수없는 경우이 경고가 표시됩니다.


또는 로그 구성 파일이로드되기 전에 내가 한 작업을 수행하고 로거를 정의 할 수 있습니다. 이것은 그들이 말하는 것과 같습니다 : "말 앞에 카트를 넣기."

코드에서 :

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

... 나중에

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


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);

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.


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.


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>

See this link for more detail :http://mariemjabloun.blogspot.com/2014/04/resolved-log4jwarn-no-appenders-could.html


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.


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>

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 .

참고URL : https://stackoverflow.com/questions/1266139/log4jwarn-no-appenders-could-be-found-for-logger-in-web-xml

반응형