forked from pyb1993/JavaRedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.java
More file actions
40 lines (37 loc) · 1.15 KB
/
Logger.java
File metadata and controls
40 lines (37 loc) · 1.15 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
package Common;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class Logger {
public static int logLevel = 0;// 只有级别大于一个级别之下的才会初夏
public static BufferedWriter out;
static {
try {
File writename = new File("/usr/local/log/pserver.log"); // 相对路径,如果没有则要建立一个新的output。txt文件
writename.createNewFile(); // 创建新文件
out = new BufferedWriter(new FileWriter(writename));
}catch (Exception e){
e.printStackTrace();
}
}
public static void log(String msg){
System.out.println(msg);
try {
out.write(msg + "\n"); // \r\n即为换行
out.flush();
}catch (Exception e){
e.printStackTrace();
}
}
public static void debug(String msg){
if(logLevel >= 1) {
System.out.println(msg);
try {
out.write(msg + "\n"); // \r\n即为换行
out.flush();
}catch (Exception e){
e.printStackTrace();
}
}
}
}