提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.tool; |
懒 |
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
|
|
5 |
import java.io.PrintWriter; |
|
6 |
import java.io.StringWriter; |
|
7 |
|
|
8 |
|
|
9 |
public class LogUtil |
|
10 |
{ |
|
11 |
private static Logger log; |
|
12 |
|
|
13 |
static |
|
14 |
{ |
|
15 |
log = Logger.getLogger(LogUtil.class); |
|
16 |
} |
|
17 |
|
|
18 |
/** |
|
19 |
* |
|
20 |
* @title getTrace |
|
21 |
* @description 输出异常详细信息 |
|
22 |
* @param t |
|
23 |
* @return String |
|
24 |
* @author ROC |
|
25 |
*/ |
|
26 |
public String getTrace(Throwable t) |
|
27 |
{ |
|
28 |
StringWriter stringWriter = new StringWriter(); |
|
29 |
PrintWriter writer = new PrintWriter(stringWriter); |
|
30 |
t.printStackTrace(writer); |
|
31 |
StringBuffer buffer = stringWriter.getBuffer(); |
|
32 |
return "抛出异常详细:"+buffer.toString(); |
|
33 |
} |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* 输出标准日志 |
|
38 |
*/ |
|
39 |
public void outputFinalLog (String startStr, String expStr,String endStr) |
|
40 |
{ |
|
41 |
StringBuffer logStr = new StringBuffer(); |
|
42 |
logStr.append(startStr); |
|
43 |
//logStr.append("\r\n"); |
|
44 |
if (expStr != null) |
|
45 |
{ |
|
46 |
logStr.append(expStr); |
|
47 |
//logStr.append("\r\n"); |
|
48 |
} |
|
49 |
logStr.append(endStr); |
|
50 |
logStr.append("\r\n"); |
|
51 |
log.info(logStr.toString()); |
|
52 |
} |
|
53 |
|
|
54 |
} |