feat(商城): 使用MDC实现接口请求调用追踪,以及用户ID记录
parent
951d8eccc5
commit
81e991323f
@ -0,0 +1,30 @@
|
||||
package com.wayn.common.task;
|
||||
|
||||
|
||||
import com.wayn.common.util.ThreadMdcUtil;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 解决子线程丢失reqest_id问题
|
||||
*/
|
||||
public class ThreadPoolExecutorMdcWrapper extends ThreadPoolTaskExecutor {
|
||||
|
||||
@Override
|
||||
public void execute(Runnable task) {
|
||||
super.execute(ThreadMdcUtil.wrap(task, MDC.getCopyOfContextMap()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
return super.submit(ThreadMdcUtil.wrap(task, MDC.getCopyOfContextMap()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> submit(Runnable task) {
|
||||
return super.submit(ThreadMdcUtil.wrap(task, MDC.getCopyOfContextMap()));
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<springProperty scope="context" name="appName" source="spring.application.name" defaultValue="dev"/>
|
||||
<property name="logPath" value="/home/logs/${appName}"/>
|
||||
<property name="pattern"
|
||||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{request_id}] [%thread] [%-5level] %logger{36}:%L %M - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoder 默认配置为PatternLayoutEncoder -->
|
||||
<encoder>
|
||||
<pattern>${pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 记录日志到文件 -->
|
||||
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${logPath}/info.log</file>
|
||||
<encoder>
|
||||
<pattern>${pattern}</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${logPath}/run.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
<!-- 只记录SQL日志 -->
|
||||
<appender name="SQL" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${logPath}/sql.log</file>
|
||||
<encoder>
|
||||
<pattern>${pattern}</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${logPath}/sql.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework" level="INFO"/>
|
||||
<logger name="io.lettuce.core" level="ERROR"/>
|
||||
<!-- logger为java中的包 -->
|
||||
<logger name="com.wayn.common.core.mapper" level="DEBUG" activity="false">
|
||||
<appender-ref ref="SQL"/>
|
||||
</logger>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue