@@ -5,10 +5,8 @@ import android.util.Log
5
5
import com.segment.analytics.kotlin.android.plugins.AndroidContextPlugin
6
6
import com.segment.analytics.kotlin.android.plugins.AndroidLifecyclePlugin
7
7
import com.segment.analytics.kotlin.core.Analytics
8
- import com.segment.analytics.kotlin.core.BaseEvent
9
8
import com.segment.analytics.kotlin.core.Configuration
10
- import com.segment.analytics.kotlin.core.platform.plugins.LogType
11
- import com.segment.analytics.kotlin.core.platform.plugins.Logger
9
+ import com.segment.analytics.kotlin.core.platform.plugins.logger.*
12
10
13
11
// A set of functions tailored to the Android implementation of analytics
14
12
@@ -54,28 +52,40 @@ public fun Analytics(
54
52
}
55
53
}
56
54
57
- // Logger instance that uses the android `Log` class
58
- object AndroidLogger : Logger() {
59
- override fun log (type : LogType , message : String , event : BaseEvent ? ) {
60
- when (type) {
61
- LogType .ERROR -> {
62
- Log .e(" AndroidAnalyticsLogger" , " message=$message , event=$event " )
55
+ // Android specific startup
56
+ private fun Analytics.startup () {
57
+ add(AndroidContextPlugin ())
58
+ add(AndroidLifecyclePlugin ())
59
+ add(AndroidLogTarget (), LoggingType .log)
60
+ remove(targetType = ConsoleTarget ::class )
61
+ }
62
+
63
+ class AndroidLogTarget : LogTarget {
64
+ override fun parseLog (log : LogMessage ) {
65
+ var metadata = " "
66
+ val function = log.function
67
+ val line = log.line
68
+ if (function != null && line != null ) {
69
+ metadata = " - $function :$line "
70
+ }
71
+
72
+ var eventString = " "
73
+ log.event.let {
74
+ eventString = " , event=$it "
75
+ }
76
+
77
+ when (log.kind) {
78
+ LogFilterKind .ERROR -> {
79
+ Log .e(" AndroidLog" , " message=${log.message}$eventString " )
63
80
}
64
- LogType .WARNING -> {
65
- Log .w(" AndroidAnalyticsLogger " , " message=$message , event= $event " )
81
+ LogFilterKind .WARNING -> {
82
+ Log .w(" AndroidLog " , " message=${log. message}$eventString " )
66
83
}
67
- LogType . INFO -> {
68
- Log .i( " AndroidAnalyticsLogger " , " message=$message , event= $event " )
84
+ LogFilterKind . DEBUG -> {
85
+ Log .d( " AndroidLog " , " message=${log. message}$eventString " )
69
86
}
70
87
}
71
88
}
72
89
73
- override fun flush () {}
74
- }
75
-
76
- // Android specific startup
77
- private fun Analytics.startup () {
78
- add(AndroidLogger )
79
- add(AndroidContextPlugin ())
80
- add(AndroidLifecyclePlugin ())
90
+ override fun flush () { }
81
91
}
0 commit comments