package cn.stylefeng.guns.plcserver.tool; import org.apache.log4j.Logger; import java.io.PrintWriter; import java.io.StringWriter; public class LogUtil { private static Logger log; static { log = Logger.getLogger(LogUtil.class); } /** * * @title getTrace * @description 输出异常详细信息 * @param t * @return String * @author ROC */ public String getTrace(Throwable t) { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); t.printStackTrace(writer); StringBuffer buffer = stringWriter.getBuffer(); return "抛出异常详细:"+buffer.toString(); } /** * 输出标准日志 */ public void outputFinalLog (String startStr, String expStr,String endStr) { StringBuffer logStr = new StringBuffer(); logStr.append(startStr); //logStr.append("\r\n"); if (expStr != null) { logStr.append(expStr); //logStr.append("\r\n"); } logStr.append(endStr); logStr.append("\r\n"); log.info(logStr.toString()); } }