Log4J

http://www.ibm.com/developerworks/cn/web/wa-lo-usertrack/index.html#Log4JConfig

 

今天突然看到log4j的MDC功能 , 觉得功能很大,很不错

import org.apache.log4j.MDC; import org.apache.commons.lang.RandomStringUtils; public class TraceUtils { public TraceUtils() { } public static void beginTrace() { String traceId = RandomStringUtils.randomAlphanumeric(8); MDC.put("traceId", traceId); } public static void beginTrace(String traceId) { MDC.put("traceId", traceId); } public static void endTrace() { MDC.remove("traceId"); } public static String getTraceIdKey() { return (String)MDC.get("traceId"); } public static final String TRACE_KEY = "traceId"; public static final int TRACE_LENGTH = 8; }

 

 

 

import javax.servlet.http.HttpServletRequest; public class CoLog { public CoLog() { } public String buildHeader(com.morningstar.oneteam.common.businessobject.DataObject.Request request, HttpServletRequest __request) { startTime = getCurrentTime(); StringBuilder sb = new StringBuilder(); sb.append("==start==").toString()); if(request != null) { } sb.append("==end==").toString()); return sb.toString(); } public String buildFooter() { StringBuilder sb = new StringBuilder(); long endTime = System.currentTimeMillis(); sb.append(("======== RESPONSE TIME: ")).append(endTime - startTime).append("ms").append(" ========").toString())).toString()); return sb.toString(); } private long getCurrentTime() { return System.currentTimeMillis(); } private static String format(String str) { } private long startTime; }

你可能感兴趣的:(Log4J)