9
9
import java .util .Objects ;
10
10
import java .util .concurrent .ConcurrentHashMap ;
11
11
import java .util .concurrent .atomic .AtomicInteger ;
12
+ import javax .annotation .Nullable ;
12
13
import org .slf4j .Marker ;
13
14
import org .slf4j .MarkerFactory ;
14
15
@@ -34,13 +35,27 @@ private LogCollector() {
34
35
this .rawLogMessages = new ConcurrentHashMap <>(maxCapacity );
35
36
}
36
37
37
- public void addLogMessage (String logLevel , String message , Throwable throwable ) {
38
+ public void addLogMessage (String logLevel , String message , @ Nullable Throwable throwable ) {
39
+ addLogMessage (logLevel , message , throwable , null );
40
+ }
41
+
42
+ /**
43
+ * Queue a log message to be sent on next telemetry flush.
44
+ *
45
+ * @param logLevel Log level (ERROR, WARN, DEBUG). Unknown log levels will be ignored.
46
+ * @param message Log message.
47
+ * @param throwable Optional throwable to attach a stacktrace.
48
+ * @param tags Optional tags to attach to the log. These are a comma-separated list, e.g.
49
+ * tag1:value1,tag2:value2
50
+ */
51
+ public void addLogMessage (
52
+ String logLevel , String message , @ Nullable Throwable throwable , @ Nullable String tags ) {
38
53
if (rawLogMessages .size () >= maxCapacity ) {
39
54
// TODO: We could emit a metric for dropped logs.
40
55
return ;
41
56
}
42
57
RawLogMessage rawLogMessage =
43
- new RawLogMessage (logLevel , message , throwable , System .currentTimeMillis () / 1000 );
58
+ new RawLogMessage (logLevel , message , throwable , tags , System .currentTimeMillis () / 1000 );
44
59
AtomicInteger count = rawLogMessages .computeIfAbsent (rawLogMessage , k -> new AtomicInteger ());
45
60
count .incrementAndGet ();
46
61
}
@@ -73,13 +88,16 @@ public static class RawLogMessage {
73
88
public final String message ;
74
89
public final String logLevel ;
75
90
public final Throwable throwable ;
91
+ public final String tags ;
76
92
public final long timestamp ;
77
93
public int count ;
78
94
79
- public RawLogMessage (String logLevel , String message , Throwable throwable , long timestamp ) {
95
+ public RawLogMessage (
96
+ String logLevel , String message , Throwable throwable , String tags , long timestamp ) {
80
97
this .logLevel = logLevel ;
81
98
this .message = message ;
82
99
this .throwable = throwable ;
100
+ this .tags = tags ;
83
101
this .timestamp = timestamp ;
84
102
}
85
103
0 commit comments