0

我怎样才能关闭class(com.service.infra)我的log4j.properties.

log4j.rootLogger=DEBUG,QuietAppender,SilentAppender,LoudAppender
log4j.appender.QuietAppender=org.apache.log4j.RollingFileAppender
log4j.appender.QuietAppender.Threshold=WARN
log4j.appender.QuietAppender.File=/Log/front-log
log4j.appender.QuietAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.QuietAppender.layout.ConversionPattern= %m%n


log4j.appender.SilentAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.SilentAppender.Threshold=INFO
log4j.appender.SilentAppender.File=/par/info,infoLog
log4j.appender.SilentAppender.DatePattern='.'dd-MM-yy
log4j.appender.SilentAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.SilentAppender.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-3p [%t] %x (%F:%L) - %m%n

在这里,我想在我的信息日志文件/par/info,infoLog中关闭警告日志,但是对于警告日志文件,它应该记录到文件/Log/front-log

4

4 回答 4

1

为您的班级设置记录器的级别:

log4j.logger.com.service.infra=ERROR,QuietAppender

这将只为您的班级记录 ERROR 和 up

于 2012-10-17T10:05:24.113 回答
0

您必须参考Log4j Log Level。这里的例子。由于使用了日志级别,警告日志Class3将关闭ERROR

log4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out"/>
        <param name="Threshold" value="DEBUG"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c] %m%n"/>
        </layout>
    </appender>
    <appender name="APPLICATION" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="/ACE-MRBS/application.log"/>
        <param name="MaxBackupIndex" value="10"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} |%5p| [%c] | %m%n"/>
        </layout>
    </appender>
    <root>
        <appender-ref ref="CONSOLE"/>
    </root>
    <logger name="your.app.test.Class1" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="APPLICATION"/>
    </logger>
    <logger name="your.app.test.Class2" additivity="false">
        <level value="WARN"/>
        <appender-ref ref="APPLICATION"/>
    </logger>
    <logger name="your.app.test.Class3" additivity="false">
        <level value="ERROR"/>
        <appender-ref ref="APPLICATION"/>
    </logger>
</log4j:configuration>
于 2012-10-17T11:39:51.063 回答
0

这是通过使用以下代码实现的

log4j.rootLogger=DEBUG,LoudAppender
log4j.logger.com.service.infra.inf=INFO,SilentAppender
log4j.logger.com.service.infra._warn=WARN,QuietAppender


log4j.appender.QuietAppender=org.apache.log4j.RollingFileAppender
log4j.appender.QuietAppender.Threshold=WARN
log4j.appender.QuietAppender.File=/Log/front-log
log4j.appender.QuietAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.QuietAppender.layout.ConversionPattern= %m%n

log4j.appender.SilentAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.SilentAppender.Threshold=INFO
log4j.appender.SilentAppender.File=/par/info,infoLog
log4j.appender.SilentAppender.DatePattern='.'dd-MM-yy
log4j.appender.SilentAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.SilentAppender.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-3p [%t] %x (%F:%L) - %m%n

log4j.appender.LoudAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LoudAppender.File=/Log/debugLog
log4j.appender.LoudAppender.DatePattern='.'dd-MM-yy
log4j.appender.LoudAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.LoudAppender.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-5p [%t] %x (%F:%L) - %m%n
于 2012-10-17T11:34:32.987 回答
0

在上面的配置中.. set threshold=ERROR,这只会将日志记录限制为 ERROR 级别,并且不会在日志中包含低于此级别的任何级别,即 WARN、DEBUG、INFO 等。

log4j.appender.QuietAppender.Threshold=WARN
于 2012-10-17T10:07:26.220 回答