43e8280d6102875eee5215ba3a0391b4531d86bf.svn-base
2.1 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
67
68
69
70
71
72
package com.espeed.log;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import com.espeed.tool.ConfigPath;
/**
*日志工具类
*/
public class LogClass {
private final static Logger logger = Logger.getLogger("syslog");
/**保存日志*/
// public static void saveLog(String domain,String loginid,String context){
// try {
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// String savepath=ConfigPath.getLogPath();
// System.setProperty("logPath",savepath+"yxyexpLog\\"+domain+"\\"+loginid+"\\"+dateFormat.format(new Date()));
//
// //项目路径
// String pathew="";
// pathew = new LogClass().getClass().getResource("/").getPath();
// pathew = pathew.replace("/classes", "");
// PropertyConfigurator.configure(pathew+"log4j.properties");// 读取log4j配置文件
// logger.info(context);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/**错误日志*/
//public static void errolog(String context,int uid){
public static void errolog(String context,String account){
FileWriter w =null;
try {
//以当前时间为日志文件名
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String nowDate=sdf.format(new Date());
//发生的时间
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowDates=sdf1.format(new Date());
//组建路径
//String savepath="D:\\yxyweberro\\"+uid;
String savepath="D:\\yxyweberro\\"+account;
File files = new File(savepath);
if (!files.exists()){
files.mkdirs();
}
//写入文件
w = new FileWriter(savepath+"/"+nowDate+".txt", true);
w.write(nowDates+": "+context+"\r\n");
w.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("日志记录异常");
}finally{
if (w != null) {
try {
w.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
}