All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zcj.web.mdc.UtilMdc Maven / Gradle / Ivy

There is a newer version: 1.1.38
Show newest version
package com.zcj.web.mdc;

import org.slf4j.MDC;

public class UtilMdc {

    // request-Header 的 key
    public static final String KEY_HEADER_LOG_ID = "X-Trace-Id";
    public static final String KEY_HEADER_CLIENT_IP = "X-Client-IP";

    // MDC 的 key
    private static final String KEY_LOG_ID = "logId";
    private static final String KEY_CLIENT_IP = "clientIp";

    public static String getLogId() {
        return MDC.get(KEY_LOG_ID);
    }

    public static String getClientIp() {
        return MDC.get(KEY_CLIENT_IP);
    }

    public static void putLogId(String logId) {
        MDC.put(KEY_LOG_ID, logId);
    }

    public static void putClientIp(String clientIp) {
        MDC.put(KEY_CLIENT_IP, clientIp);
    }

    public static void removeLogId() {
        MDC.remove(KEY_LOG_ID);
    }

    public static void removeClientIp() {
        MDC.remove(KEY_CLIENT_IP);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy