MDC模式下log4j的配置
TLog中log4j的MDC占位符为%X{tl}
你可以在配置文件的pattern里定义,无论是同步模式和异步模式都一样,样例如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<!--控制台日志-->
<!--这里替换成AspectLog4jPatternLayout-->
<appender name="Console" class="org.apache.log4j.ConsoleAppender">
<layout class="com.yomahub.tlog.core.enhance.log4j.AspectLog4jPatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %X{tl} [%t] [%p] %m >> %c:%L%n"/>
</layout>
</appender>
<!--文件日志-->
<!--同步日志:只需要替换为AspectLog4jPatternLayout即可-->
<appender name="SyncFile" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="./logs/log4j-sync-mdc.log"/>
<layout class="com.yomahub.tlog.core.enhance.log4j.AspectLog4jPatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %X{tl} [%t] [%p] %m >> %c:%L%n"/>
</layout>
</appender>
<root>
<priority value="info" />
<appender-ref ref="Console"/>
<appender-ref ref="SyncFile"/>
</root>
</log4j:configuration>
帮助我们改善文档 (opens new window)
last update: 2022/09/21, 16:00:22