首页 > 代码库 > 日志通用类
日志通用类
/**
* 跟踪日志,trace.xml记录
* @param className 类
* @param methodName 方法
* @param msg 消息
*/
public static void trace(String className,String methodName,String msg){ Logger traceLogger = PafaCoreContexton.getInstance().getTracer(); traceLogger.log(ActionContext.getCurrentUmId(), Level.INFO ,className, methodName, msg);
}
/**
* 记录error日志
*
* @param className -
* 抛出异常的类名
* @param methodName -
* 抛出异常的方法名
* @param t -
* 抛出的异常
*/
public static void logError(String className, String methodName, Throwable t) {
PafaApplicationContext coreContext = PafaCoreContexton.getInstance();
Logger errorLogger = coreContext.getErrorLogger();
errorLogger.log(ActionContext.getCurrentUmId(), Level.SEVERE, className, methodName, "", t, "");
}
/**
* Description: 获取异常堆栈信息
* @param throwable
* @return
*/
public static String getStackTrace(Throwable throwable) {
if (throwable == null){
return "";
}
String rtn = throwable.getStackTrace().toString();
Writer writer = null;
PrintWriter printWriter = null;
try {
writer = new StringWriter();
printWriter = new PrintWriter(writer);
throwable.printStackTrace(printWriter);
printWriter.flush();
writer.flush();
rtn = writer.toString();
} catch (IOException e) {
LoggerUtil.logError("com.paic.egis.sales.common.util.LoggerUtil", "getStackTrace", e);
} catch (Exception ex) {
LoggerUtil.logError("com.paic.egis.sales.common.util.LoggerUtil", "getStackTrace", ex);
}finally{
if(printWriter != null){
printWriter.close();
}
try {
if(writer != null){
writer.close();
}
} catch (IOException e) {
LoggerUtil.logError("com.paic.egis.sales.common.util.LoggerUtil", "getStackTrace", e);
}
}
return rtn;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map fecthParamFromRequest(HttpServletRequest request){
Map paramMap = new HashMap();
try{
synchronized(request){
Enumeration paramEnum = request.getParameterNames();
while(paramEnum.hasMoreElements()){
String paramName = (String)paramEnum.nextElement();
String messageContent = request.getParameter(paramName);
paramMap.put(paramName,messageContent);
}
}
}catch(Exception e){
}
return paramMap;
}
日志通用类