forked from Shaddy1884/requiem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneLineFormatter.java
36 lines (34 loc) · 991 Bytes
/
OneLineFormatter.java
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
import java.util.logging.*;
import java.io.*;
import java.text.*;
import java.util.Date;
class OneLineFormatter extends Formatter {
private static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
public String format(LogRecord r) {
StringBuilder s = new StringBuilder();
s.append(dateFormatter.format(new Date(r.getMillis())));
s.append(" ");
s.append(r.getLevel());
s.append(" ");
Throwable t = r.getThrown();
if (t == null) {
s.append(r.getSourceClassName());
s.append(":");
s.append(r.getSourceMethodName());
s.append(" ");
s.append(r.getMessage());
s.append("\n");
} else {
if (!r.getMessage().equals("")) {
s.append(r.getMessage());
s.append(" ");
}
CharArrayWriter c = new CharArrayWriter();
PrintWriter p = new PrintWriter(c);
t.printStackTrace(p);
p.flush();
s.append(c.toString());
}
return s.toString();
}
}