e9e6d52c3b2adfb1964a82bb2eea15463a401fa2.svn-base
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.espeed.reading.util;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
*
* @项目名称: 邮件跟踪系统
* @版权所有: 深圳市科飞时速网络技术有限公司(0755-88843776)
* @技术支持: info@21gmail.com
* @单元名称: 日志工具类
* @开始时间: 2018-5-23
* @开发人员: 杨志钊
*/
public class LogUtil {
private final static Logger logger = Logger.getLogger("syslog");
private final static String savePath = ConfigPath.getLogSavePath();
private final static SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
private static String path = null;
static {
try {
path = LogUtil.class.getClassLoader().getResource("").toURI()
.getPath().replace("classes/", "")
+ "log4j.properties";
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
/** 保存日志 */
public static void saveInfoLog(Object userId, Exception e) {
System.setProperty("logPath", savePath + "/" + userId + "/"
+ dateFormat.format(new Date()));
// 读取log4j配置文件
PropertyConfigurator.configure(path);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String info = sw.toString();
logger.error(info);
}
/** 保存日志 */
public static void saveInfoLog(Object userId, String info) {
System.setProperty("logPath", savePath + "/" + userId + "/"
+ dateFormat.format(new Date()));
// 读取log4j配置文件
PropertyConfigurator.configure(path);
logger.error(info);
}
}