log4j configuration not used

こ雲淡風輕ζ 提交于 2019-12-08 03:15:32

问题


My log4j logger does not want to use the log4j.xml file to be configured. This file is located in the src folder and looks like that:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
    <appender name="ROLLING" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="C:\debug\myproject\logfile.log" />
        <param name="MaxFileSize" value="10024KB" />
        <param name="MaxBackupIndex" value="5" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L)  -%m%n" />
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG" />
            <param name="LevelMax" value="FATAL" />
        </filter>
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="ROLLING" />
    </root>
</log4j:configuration>

But logfile.log is still empty and there is no "DEBUG" line in the console.

NB: it is a Java EE project on JBoss 7.1.0 and using Struts2.


回答1:


The following answer is not entirely mine. It was posted in the question itself by the OP, so I'm moving it into this community wiki answer.


I resolved it by explicitely configuring the logging configuration.

Note that you won't be able to change the configuration at runtime if you configure it using a file.

For more information, see: https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F




回答2:


Make sure the log4j.xml file is located in the /WEB-INF/classes directory of your web application.




回答3:


The problem was with the log file. If you use the absolute file name make sure to replace backslashes with slash. For example

<param name="File" value="C:/debug/myproject/logfile.log" /> 


来源:https://stackoverflow.com/questions/15026408/log4j-configuration-not-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!