log4j 2 - configuration issue

前端 未结 12 737
执笔经年
执笔经年 2020-12-10 12:34

I am trying to configure log4j 2.0 to report logs.

My config is saved as log4j2.xml and this is its content:

  

        
相关标签:
12条回答
  • 2020-12-10 12:53

    I had similar problem. I put the file under src folder and it worked. I did not mention any package name in the log4j2.xml file.

    0 讨论(0)
  • 2020-12-10 12:54

    you should put your log4j2.xml into the classpath.

    or set "log4j.configurationFile" system property to force to use your log4j2.xml

    Please refer to: http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration

    0 讨论(0)
  • 2020-12-10 12:55

    I also faced the same problem.I kept my log4j2.xml file in System environment variable.

    Variable name : sys_logroot Variable value : D:\user\gouse

    and no logs are created for me.

    use the system variable-Dlog4j.configurationFile=path/to/log4j2.xmlSee here

    This solve my problem

    0 讨论(0)
  • 2020-12-10 12:56

    place log4j2.xml file under src/main/resources. It works

    0 讨论(0)
  • 2020-12-10 12:59

    I had the problem, I tried some solutions, but only this worked to me:

    Go to web.xml, and add this parameter:

    <context-param>
        <param-name>log4jConfiguration</param-name>
        <param-value>log4j2.xml</param-value>
    </context-param>
    
    0 讨论(0)
  • 2020-12-10 13:00

    In the documentation of log4j 2: http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration

    "If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath."

    but it is not working with classpath. Instead if we keep it in src folder, then it is working.

    <context-param>
        <param-name>log4jConfiguration</param-name>
        <param-value>log4j2.xml</param-value>
    </context-param>
    

    similar problem is mentioned here : https://issues.apache.org/jira/browse/LOG4J2-357

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