没有使用log4j配置 [英] log4j configuration not used

查看:149
本文介绍了没有使用log4j配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的log4j记录器不想使用要配置的 log4j.xml 文件。此文件位于 src 文件夹中,看起来像这样:

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>

但是logfile.log仍为空,控制台中没有DEBUG行。

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

注意:它是JBoss 7.1.0上的Java EE项目并使用Struts2。

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

推荐答案

以下答案并不完全是我的。它由OP发布在问题本身中,所以我将它移到这个社区wiki答案中。

我通过明确配置日志记录配置解决了这个问题。

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.

有关详细信息,请参阅: https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadof theloggingsubsystemconfiguration%3F

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

这篇关于没有使用log4j配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆