1. 程式人生 > >Log4j2、Log4j、Logback自定義Appender實現

Log4j2、Log4j、Logback自定義Appender實現

logback:

<!--異常收集 -->

<appender name="gwarn"class="com.duowan.gwarn.sdk.GwarnLogbackAppender">

         <filterclass="ch.qos.logback.classic.filter.ThresholdFilter">

                   <level>ERROR</level>

         </filter>

</appender>

<root>

         <levelvalue="INFO" />

         <appender-refref="gwarn" />

</root>

log4j:

log4j.rootLogger=INFO,gwarn

log4j.appender.gwarn=com.duowan.gwarn.sdk.GwarnLog4jAppender

log4j.appender.gwarn.Threshold = ERROR

log4j2:

<configurationpackages="com.duowan.gwarn.sdk">

         <appenders>

                   <Gwarnname="gwarn">

                            <ThresholdFilterlevel="error" onMatch="ACCEPT" onMismatch="DENY"/>

                   </Gwarn>

         </appenders>

         <loggers>

                   <rootlevel="info">

                            <appender-refref="gwarn" />

                   </root>

         </loggers>

</configuration>