forked from processing/processing-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogEntry.java
More file actions
59 lines (51 loc) · 1.57 KB
/
LogEntry.java
File metadata and controls
59 lines (51 loc) · 1.57 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
package processing.mode.android;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class LogEntry {
public static enum Severity {
Verbose(false), Debug(false), Info(false), Warning(true), Error(true), Fatal(
true);
public final boolean useErrorStream;
private Severity(final boolean useErrorStream) {
this.useErrorStream = useErrorStream;
}
private static Severity fromChar(final char c) {
if (c == 'V') {
return Verbose;
} else if (c == 'D') {
return Debug;
} else if (c == 'I') {
return Info;
} else if (c == 'W') {
return Warning;
} else if (c == 'E') {
return Error;
} else if (c == 'F') {
return Fatal;
} else {
throw new IllegalArgumentException("I don't know how to interpret '"
+ c + "' as a log severity");
}
}
}
public final Severity severity;
public final String source;
public final int pid;
public final String message;
private static final Pattern PARSER = Pattern
.compile("^([VDIWEF])/([^\\(\\s]+)\\s*\\(\\s*(\\d+)\\): (.+)$");
public LogEntry(final String line) {
final Matcher m = PARSER.matcher(line);
if (!m.matches()) {
throw new RuntimeException("I can't understand log entry\n" + line);
}
this.severity = Severity.fromChar(m.group(1).charAt(0));
this.source = m.group(2);
this.pid = Integer.parseInt(m.group(3));
this.message = m.group(4);
}
@Override
public String toString() {
return severity + "/" + source + "(" + pid + "): " + message;
}
}