-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCrashTracker.java
67 lines (52 loc) · 1.67 KB
/
CrashTracker.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
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
package com.team254.lib.util;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.UUID;
/**
* Tracks start-up and caught crash events, logging them to a file which dosn't roll over
*/
public class CrashTracker {
private static final UUID RUN_INSTANCE_UUID = UUID.randomUUID();
public static void logRobotConstruction() {
logMarker("robot startup");
}
public static void logRobotInit() {
logMarker("robot init");
}
public static void logTeleopInit() {
logMarker("teleop init");
}
public static void logAutoInit() {
logMarker("auto init");
}
public static void logDisabledInit() {
logMarker("disabled init");
}
public static void logTestInit() {
logMarker("test init");
}
public static void logThrowableCrash(Throwable throwable) {
logMarker("Exception", throwable);
}
private static void logMarker(String mark) {
logMarker(mark, null);
}
private static void logMarker(String mark, Throwable nullableException) {
try (PrintWriter writer = new PrintWriter(new FileWriter("/home/lvuser/crash_tracking.txt", true))) {
writer.print(RUN_INSTANCE_UUID.toString());
writer.print(", ");
writer.print(mark);
writer.print(", ");
writer.print(new Date().toString());
if (nullableException != null) {
writer.print(", ");
nullableException.printStackTrace(writer);
}
writer.println();
} catch (IOException e) {
e.printStackTrace();
}
}
}