1
+ @file:Suppress(" INVISIBLE_MEMBER" , " INVISIBLE_REFERENCE" )
2
+
1
3
package io.sentry.android.timber
2
4
3
5
import android.util.Log
@@ -17,23 +19,15 @@ public class SentryTimberTree(
17
19
private val minEventLevel : SentryLevel ,
18
20
private val minBreadcrumbLevel : SentryLevel
19
21
) : Timber.Tree() {
20
- private val pendingTag = ThreadLocal <String ?>()
21
-
22
- private fun retrieveTag (): String? {
23
- val tag = pendingTag.get()
24
- if (tag != null ) {
25
- this .pendingTag.remove()
26
- }
27
- return tag
28
- }
29
22
30
23
/* * Log a verbose message with optional format args. */
31
24
override fun v (
32
25
message : String? ,
33
26
vararg args : Any?
34
27
) {
28
+ val tag = explicitTag.get()
35
29
super .v(message, * args)
36
- logWithSentry(Log .VERBOSE , null , message, * args)
30
+ logWithSentry(Log .VERBOSE , null , message, tag, * args)
37
31
}
38
32
39
33
/* * Log a verbose exception and a message with optional format args. */
@@ -42,23 +36,26 @@ public class SentryTimberTree(
42
36
message : String? ,
43
37
vararg args : Any?
44
38
) {
39
+ val tag = explicitTag.get()
45
40
super .v(t, message, * args)
46
- logWithSentry(Log .VERBOSE , t, message, * args)
41
+ logWithSentry(Log .VERBOSE , t, message, tag, * args)
47
42
}
48
43
49
44
/* * Log a verbose exception. */
50
45
override fun v (t : Throwable ? ) {
46
+ val tag = explicitTag.get()
51
47
super .v(t)
52
- logWithSentry(Log .VERBOSE , t, null )
48
+ logWithSentry(Log .VERBOSE , t, null , tag, null )
53
49
}
54
50
55
51
/* * Log a debug message with optional format args. */
56
52
override fun d (
57
53
message : String? ,
58
54
vararg args : Any?
59
55
) {
56
+ val tag = explicitTag.get()
60
57
super .d(message, * args)
61
- logWithSentry(Log .DEBUG , null , message, * args)
58
+ logWithSentry(Log .DEBUG , null , message, tag, * args)
62
59
}
63
60
64
61
/* * Log a debug exception and a message with optional format args. */
@@ -67,23 +64,26 @@ public class SentryTimberTree(
67
64
message : String? ,
68
65
vararg args : Any?
69
66
) {
67
+ val tag = explicitTag.get()
70
68
super .d(t, message, * args)
71
- logWithSentry(Log .DEBUG , t, message, * args)
69
+ logWithSentry(Log .DEBUG , t, message, tag, * args)
72
70
}
73
71
74
72
/* * Log a debug exception. */
75
73
override fun d (t : Throwable ? ) {
74
+ val tag = explicitTag.get()
76
75
super .d(t)
77
- logWithSentry(Log .DEBUG , t, null )
76
+ logWithSentry(Log .DEBUG , t, null , tag, null )
78
77
}
79
78
80
79
/* * Log an info message with optional format args. */
81
80
override fun i (
82
81
message : String? ,
83
82
vararg args : Any?
84
83
) {
84
+ val tag = explicitTag.get()
85
85
super .d(message, * args)
86
- logWithSentry(Log .INFO , null , message, * args)
86
+ logWithSentry(Log .INFO , null , message, tag, * args)
87
87
}
88
88
89
89
/* * Log an info exception and a message with optional format args. */
@@ -92,23 +92,26 @@ public class SentryTimberTree(
92
92
message : String? ,
93
93
vararg args : Any?
94
94
) {
95
+ val tag = explicitTag.get()
95
96
super .i(t, message, * args)
96
- logWithSentry(Log .INFO , t, message, * args)
97
+ logWithSentry(Log .INFO , t, message, tag, * args)
97
98
}
98
99
99
100
/* * Log an info exception. */
100
101
override fun i (t : Throwable ? ) {
102
+ val tag = explicitTag.get()
101
103
super .i(t)
102
- logWithSentry(Log .INFO , t, null )
104
+ logWithSentry(Log .INFO , t, null , tag, null )
103
105
}
104
106
105
107
/* * Log a warning message with optional format args. */
106
108
override fun w (
107
109
message : String? ,
108
110
vararg args : Any?
109
111
) {
112
+ val tag = explicitTag.get()
110
113
super .w(message, * args)
111
- logWithSentry(Log .WARN , null , message, * args)
114
+ logWithSentry(Log .WARN , null , message, tag, * args)
112
115
}
113
116
114
117
/* * Log a warning exception and a message with optional format args. */
@@ -117,23 +120,26 @@ public class SentryTimberTree(
117
120
message : String? ,
118
121
vararg args : Any?
119
122
) {
123
+ val tag = explicitTag.get()
120
124
super .w(t, message, * args)
121
- logWithSentry(Log .WARN , t, message, * args)
125
+ logWithSentry(Log .WARN , t, message, tag, * args)
122
126
}
123
127
124
128
/* * Log a warning exception. */
125
129
override fun w (t : Throwable ? ) {
130
+ val tag = explicitTag.get()
126
131
super .w(t)
127
- logWithSentry(Log .WARN , t, null )
132
+ logWithSentry(Log .WARN , t, null , tag, null )
128
133
}
129
134
130
135
/* * Log an error message with optional format args. */
131
136
override fun e (
132
137
message : String? ,
133
138
vararg args : Any?
134
139
) {
140
+ val tag = explicitTag.get()
135
141
super .e(message, * args)
136
- logWithSentry(Log .ERROR , null , message, * args)
142
+ logWithSentry(Log .ERROR , null , message, tag, * args)
137
143
}
138
144
139
145
/* * Log an error exception and a message with optional format args. */
@@ -142,23 +148,26 @@ public class SentryTimberTree(
142
148
message : String? ,
143
149
vararg args : Any?
144
150
) {
151
+ val tag = explicitTag.get()
145
152
super .e(t, message, * args)
146
- logWithSentry(Log .ERROR , t, message, * args)
153
+ logWithSentry(Log .ERROR , t, message, tag, * args)
147
154
}
148
155
149
156
/* * Log an error exception. */
150
157
override fun e (t : Throwable ? ) {
158
+ val tag = explicitTag.get()
151
159
super .e(t)
152
- logWithSentry(Log .ERROR , t, null )
160
+ logWithSentry(Log .ERROR , t, null , tag, null )
153
161
}
154
162
155
163
/* * Log an assert message with optional format args. */
156
164
override fun wtf (
157
165
message : String? ,
158
166
vararg args : Any?
159
167
) {
168
+ val tag = explicitTag.get()
160
169
super .wtf(message, * args)
161
- logWithSentry(Log .ASSERT , null , message, * args)
170
+ logWithSentry(Log .ASSERT , null , message, tag, * args)
162
171
}
163
172
164
173
/* * Log an assert exception and a message with optional format args. */
@@ -167,14 +176,16 @@ public class SentryTimberTree(
167
176
message : String? ,
168
177
vararg args : Any?
169
178
) {
179
+ val tag = explicitTag.get()
170
180
super .wtf(t, message, * args)
171
- logWithSentry(Log .ASSERT , t, message, * args)
181
+ logWithSentry(Log .ASSERT , t, message, tag, * args)
172
182
}
173
183
174
184
/* * Log an assert exception. */
175
185
override fun wtf (t : Throwable ? ) {
186
+ val tag = explicitTag.get()
176
187
super .wtf(t)
177
- logWithSentry(Log .ASSERT , t, null )
188
+ logWithSentry(Log .ASSERT , t, null , tag, null )
178
189
}
179
190
180
191
/* * Log at `priority` a message with optional format args. */
@@ -183,8 +194,9 @@ public class SentryTimberTree(
183
194
message : String? ,
184
195
vararg args : Any?
185
196
) {
197
+ val tag = explicitTag.get()
186
198
super .log(priority, message, * args)
187
- logWithSentry(priority, null , message, * args)
199
+ logWithSentry(priority, null , message, tag, * args)
188
200
}
189
201
190
202
/* * Log at `priority` an exception and a message with optional format args. */
@@ -194,8 +206,9 @@ public class SentryTimberTree(
194
206
message : String? ,
195
207
vararg args : Any?
196
208
) {
209
+ val tag = explicitTag.get()
197
210
super .log(priority, t, message, * args)
198
- logWithSentry(priority, t, message, * args)
211
+ logWithSentry(priority, t, message, tag, * args)
199
212
}
200
213
201
214
/* * Log at `priority` an exception. */
@@ -204,26 +217,16 @@ public class SentryTimberTree(
204
217
t : Throwable ?
205
218
) {
206
219
super .log(priority, t)
207
- logWithSentry(priority, t, null )
208
- }
209
-
210
- override fun log (
211
- priority : Int ,
212
- tag : String? ,
213
- message : String ,
214
- t : Throwable ?
215
- ) {
216
- pendingTag.set(tag)
220
+ logWithSentry(priority, t, null , tag, null )
217
221
}
218
222
219
223
private fun logWithSentry (
220
224
priority : Int ,
221
225
throwable : Throwable ? ,
222
226
message : String? ,
227
+ tag : String? ,
223
228
vararg args : Any?
224
229
) {
225
- val tag = retrieveTag()
226
-
227
230
if (message.isNullOrEmpty() && throwable == null ) {
228
231
return // Swallow message if it's null and there's no throwable
229
232
}
@@ -238,7 +241,7 @@ public class SentryTimberTree(
238
241
}
239
242
240
243
captureEvent(level, tag, sentryMessage, throwable)
241
- addBreadcrumb(level, sentryMessage, throwable)
244
+ addBreadcrumb(level, sentryMessage, tag, throwable)
242
245
}
243
246
244
247
/* *
@@ -279,12 +282,13 @@ public class SentryTimberTree(
279
282
private fun addBreadcrumb (
280
283
sentryLevel : SentryLevel ,
281
284
msg : Message ,
285
+ tag : String? ,
282
286
throwable : Throwable ?
283
287
) {
284
288
// checks the breadcrumb level
285
289
if (isLoggable(sentryLevel, minBreadcrumbLevel)) {
286
290
val throwableMsg = throwable?.message
287
- val breadCrumb = when {
291
+ val breadcrumb = when {
288
292
msg.message != null -> Breadcrumb ().apply {
289
293
level = sentryLevel
290
294
category = " Timber"
@@ -295,11 +299,24 @@ public class SentryTimberTree(
295
299
}
296
300
else -> null
297
301
}
298
-
299
- breadCrumb?.let { scopes.addBreadcrumb(it) }
302
+ if (breadcrumb != null ) {
303
+ if (tag != null ) {
304
+ breadcrumb.setData(" tag" , tag)
305
+ }
306
+ scopes.addBreadcrumb(breadcrumb)
307
+ }
300
308
}
301
309
}
302
310
311
+ override fun log (
312
+ priority : Int ,
313
+ tag : String? ,
314
+ message : String ,
315
+ t : Throwable ?
316
+ ) {
317
+ // no-op
318
+ }
319
+
303
320
/* *
304
321
* Converts from Timber priority to SentryLevel.
305
322
* Fallback to SentryLevel.DEBUG.
0 commit comments