LOG4J簡單配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="info">
    <appenders>
        <!--默認按天&按512M文件大小切分日誌,默認最多保留30個日誌文件,非阻塞模式-->
        <XMDFile name="infoAppender" fileName="info.log" sizeBasedTriggeringSize="512M"
                 rolloverMax="30">
            <Filters>
                <ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
                <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
        </XMDFile>

        <XMDFile name="warnAppender" fileName="warn.log" sizeBasedTriggeringSize="512M"
                 rolloverMax="30">
            <Filters>
                <ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
                <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
        </XMDFile>

        <XMDFile name="errorAppender" fileName="error.log" sizeBasedTriggeringSize="512M"
                 rolloverMax="30">
            <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
        </XMDFile>

        <!--日誌遠程上報-->
        <Scribe name="ScribeAppender">
            <!--遠程日誌默認使用appkey做爲日誌名(app.properties文件中的app.name字段),也可自定義scribeCategory屬性,scribeCategory優先級高於appkey-->
            <LcLayout/>
        </Scribe>
        <Async name="ScribeAsyncAppender" blocking="false">
            <AppenderRef ref="ScribeAppender"/>
        </Async>

        <CatAppender name="catAppender"/>

    </appenders>

    <loggers>
        <!--遠程日誌-->
        <logger name="scribe" level="info" additivity="false">
            <appender-ref ref="ScribeAsyncAppender" />
        </logger>

        <root level="info">
            <appender-ref ref="infoAppender"/>
            <appender-ref ref="warnAppender"/>
            <appender-ref ref="errorAppender"/>
            <appender-ref ref="catAppender"/>
        </root>
    </loggers>
</configuration>
相關文章
相關標籤/搜索