Helius
2020-12-17 f76c9c5beb39916771402de95f05be18f39a9db6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.matrix.core.tools;
 
import org.apache.log4j.MDC;
 
/**
 * 日志追踪
 * 
 * @author JIANGYOUYAO
 * @email 935090232@qq.com
 * @date 2017年11月27日
 */
public class MdcUtil {
    private static final String TR_KEY = "Tr";
 
    public static void setRequestId() {
        MDC.clear();
        MDC.put(TR_KEY, "TR = " + StringUtils.getRandomString(16) + "");
    }
 
    public static void clearRequestId() {
        MDC.clear();
    }
 
    public static String getMdc() {
        return (String) MDC.get(TR_KEY);
    }
 
}