2

下面是我们在我公司使用的 log4j.xml 文件的代码。我们一直在尝试将其更改为仅记录 org.xxxx 中带有 make 的类的输出。有人可以让我知道这是否可以做到以及如何做到这一点

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
        </layout>
    </appender>


    <appender name="logfile" class="org.apache.log4j.FileAppender">
        <param name="File" value="logs/disater_relief.log" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
        </layout>
    </appender>


    <appender name="rollinglogfile" class="org.apache.log4j.RollingFileAppender">
        <param name="file" value="logs/ennrollment.log" />
        <param name="immediateFlush" value="true" />
        <param name="append" value="true" />
        <param name="maxFileSize" value="1MB" />
        <param name="maxBackupIndex" value="3" />

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
        </layout>

    </appender>

    <appender name="dailyrollinglogfile" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="logs/ennrollment.log" />
        <param name="immediateFlush" value="true" />
        <param name="append" value="true" />
        <param name="datePattern" value=" '.' yyyy-MM-dd "/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
        </layout>

    </appender>

    <root>
        <priority value="debug" />
        <appender-ref ref="console" />
        <appender-ref ref="dailyrollinglogfile" />
    </root>

</log4j:configuration>
4

2 回答 2

4

您的 root logger 定义了所有组件的调试日志记录。您应该将其更改为warn(因此您仍然会看到警告)并为您自己的组件添加一个额外的记录器:

<logger name="com.xxx.mycomponent">
  <level value="trace"/>

  <!-- appenders ... -->

</logger>

<root>
    <priority value="warn" />
    <appender-ref ref="console" />
    <appender-ref ref="dailyrollinglogfile" />
</root>
于 2012-08-16T17:09:37.330 回答
1

只需关闭您不想在日志中看到的包的日志记录...

<!-- Limit JBoss categories -->
<category name="org.jboss">
   <priority value="OFF"/>
</category>
于 2012-08-16T17:05:49.157 回答