-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCountlyTree.kt
More file actions
39 lines (32 loc) · 1.17 KB
/
CountlyTree.kt
File metadata and controls
39 lines (32 loc) · 1.17 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
package info.hannes.timber
import android.util.Log
import info.hannes.countly.Analytics
class CountlyTree(private val analytics: Analytics, private val serverIgnoreToken: String? = null) : DebugFormatTree() {
// some regex explanation :
// $t sign to search
// . any char
// + minimum once
// ? null or once
// | or
// # beginning with #
// [^#] any char except #
// *$ till end of line
// short variable to avoid lint warning "Duplicate char n inside Character class" in following line
private val t = serverIgnoreToken
private val regex: Regex = "$t.+?$t|$t[^$t]*$".toRegex()
override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) {
// we ignore INFO, DEBUG and VERBOSE
if (priority <= Log.INFO) {
return
}
var localMessage = message
serverIgnoreToken?.let {
localMessage = regex.replace(message, "")
}
when {
t != null -> analytics.recordError(t)
priority == Log.WARN -> analytics.recordEvent(localMessage)
else -> analytics.recordError(localMessage)
}
}
}