Log4j框架适配器
# 同步日志
只需要把layout
的实现类换掉就可以了
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<!--替换成AspectLog4jPatternLayout-->
<layout class="com.yomahub.tlog.core.enhance.log4j.AspectLog4jPatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} [%p] %m >> %c:%L%n"/>
</layout>
</appender>
<appender name="fileout" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="./logs/test.log"/>
<!--替换成AspectLog4jPatternLayout-->
<layout class="com.yomahub.tlog.core.enhance.log4j.AspectLog4jPatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} [%p] %m >> %c:%L%n"/>
</layout>
</appender>
<root>
<priority value="info" />
<appender-ref ref="stdout"/>
<appender-ref ref="fileout"/>
</root>
</log4j:configuration>
# 异步日志
只要把appender
的实现类替换掉就行了
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} [%p] %m >> %c:%L%n"/>
</layout>
</appender>
<appender name="fileout" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="./logs/log4j-dubbo-provider.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} [%p] %m >> %c:%L%n"/>
</layout>
</appender>
<!--这里替换成AspectLog4jAsyncAppender-->
<appender name="asyncFileout" class="com.yomahub.tlog.core.enhance.log4j.async.AspectLog4jAsyncAppender">
<appender-ref ref="fileout"/>
</appender>
<root>
<priority value="info" />
<appender-ref ref="stdout"/>
<appender-ref ref="asyncFileout"/>
</root>
</log4j:configuration>
帮助我们改善文档 (opens new window)
last update: 2022/09/21, 16:00:22