public class LogBusinessIdUtils {
private static final ThreadLocal<String> businessLocal = new ThreadLocal<String>();
/**
* 返回当前线程对应的uuid
* @return
*/
public static String getCurBusinessId(){
String uuid = businessLocal.get();
if(StringUtils.isEmpty(uuid)){
uuid = UUID.randomUUID().toString().replace("-", "");
businessLocal.set(uuid);
}
return uuid;
}
/**
* 给当前线程重新设置
*/
public static void clear(){
businessLocal.set(null);
}
}
打印日志 log.error("业务标示ID["+LogBusinessIdUtils.getCurBusinessId()+"],"+str)
脱敏
String.valueOf(object).replaceAll("(?<=(mobile|mobileNo|phone|address|name|bank|taxId|acount)\\\\?\"?:\\\\?\"?)(\\d|\\w|[\\u4e00-\\u9fa5])+(?=)", "***");