com.dingtalk.baymax.framework.sdk.mercury.util.TraceUtils Maven / Gradle / Ivy
package com.dingtalk.baymax.framework.sdk.mercury.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.baymax.framework.sdk.mercury.model.TraceBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;
/**
* @author niumingjie.nmj
* @date 2023/8/15
*/
public class TraceUtils {
private static final Logger bizLogger = LoggerFactory.getLogger("DESENSITIZATION_SERVICE_LOGGER");
public static void info(String className, String method, String msg, Object... obj) {
TraceBean traceBean = new TraceBean();
traceBean.setTraceTime(System.currentTimeMillis());
traceBean.setMethodExecute("output");
traceBean.setOpObject("LLM_Chain");
traceBean.setClassName(className);
traceBean.setMethodName(method);
traceBean.setStatus("-");
traceBean.setRt("-");
JSONObject result = new JSONObject();
result.put("msg", MessageFormatter.arrayFormat(msg, obj).getMessage());
traceBean.setResult(JSON.toJSONString(result));
//勿动
bizLogger.info("{}", JSON.toJSONString(traceBean));
}
public static void warning(String className, String method, String msg, Object... obj) {
TraceBean traceBean = new TraceBean();
traceBean.setTraceTime(System.currentTimeMillis());
traceBean.setMethodExecute("output");
traceBean.setOpObject("LLM_Chain");
traceBean.setClassName(className);
traceBean.setMethodName(method);
traceBean.setStatus("-");
traceBean.setRt("-");
JSONObject result = new JSONObject();
result.put("msg", MessageFormatter.arrayFormat(msg, obj).getMessage());
traceBean.setResult(JSON.toJSONString(result));
//勿动
bizLogger.warn("{}", JSON.toJSONString(traceBean));
}
public static void error(String className, String method, String msg, Throwable t) {
TraceBean traceBean = new TraceBean();
traceBean.setTraceTime(System.currentTimeMillis());
traceBean.setClassName(className);
traceBean.setMethodName(method);
traceBean.setStatus("FAILED");
traceBean.setMethodExecute("output");
traceBean.setOpObject("LLM_Chain");
traceBean.setStatus("-");
traceBean.setRt("-");
JSONObject result = new JSONObject();
result.put("msg", msg);
result.put("Throwable", JSON.toJSONString(t));
traceBean.setResult(JSON.toJSONString(result));
//勿动
bizLogger.error("{}", JSON.toJSONString(traceBean));
}
}