package cn.freemud.utils;


import org.apache.commons.lang.StringUtils;

import java.util.UUID;

public class LogTreadLocal {
    private final static ThreadLocal<String> trackingNoThreadLocal = new InheritableThreadLocal<>();

    public static void setTrackingNo(String trackingNo) {
        LogTreadLocal.trackingNoThreadLocal.set(trackingNo);
    }

    public static String getTrackingNo() {
        String trac = LogTreadLocal.trackingNoThreadLocal.get();
        if(StringUtils.isBlank(trac)) {
            trac = UUID.randomUUID().toString().replaceAll("-", "");
            LogTreadLocal.trackingNoThreadLocal.set(trac);
        }
        return trac;
    }

    public static void removeTrackingNo() {
        LogTreadLocal.trackingNoThreadLocal.remove();
    }
}