From a5afd2c917f0287b493cc2d21a39336e202ac4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E6=97=AD=E9=94=90?= Date: Wed, 22 Sep 2021 22:44:24 +0800 Subject: [PATCH] feat:update log format --- .../java/com/pengxr/easytrack/core/EasyTrack.kt | 17 ++++++++++------- .../com/pengxr/easytrack/util/EasyTrackUtils.kt | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/easytrack/src/main/java/com/pengxr/easytrack/core/EasyTrack.kt b/easytrack/src/main/java/com/pengxr/easytrack/core/EasyTrack.kt index 841fa11..d03ce4c 100644 --- a/easytrack/src/main/java/com/pengxr/easytrack/core/EasyTrack.kt +++ b/easytrack/src/main/java/com/pengxr/easytrack/core/EasyTrack.kt @@ -71,26 +71,29 @@ internal fun Any.doTrackEvent(eventName: String, otherParams: TrackParams? = nul return otherParams } // 3. Log. - if (EasyTrack.debug) { - val logStr = StringBuilder().apply { + val logStrBuilder = if (EasyTrack.debug) { + StringBuilder().apply { append(" ") append("\nonEvent:$eventName") for ((key, value) in params) { append("\n$key = $value") } - append("\n------------------------------------------------------") - }.toString() - Log.d(TAG, logStr) + } + } else { + null } // 4. Do event reporting. for (provider in EasyTrack.providers) { if (!provider.enabled) { - Log.d(TAG, "Try track event $eventName, but the provider is disabled.") + logStrBuilder?.append("\nTry track event $eventName, but the provider is disabled.") continue } - Log.d(TAG, "Try track event $eventName with provider ${provider.name}.") + logStrBuilder?.append("\nTry track event $eventName with provider ${provider.name}.") provider.onEvent(eventName, params) } + logStrBuilder?.append("\n------------------------------------------------------")?.also { + Log.d(TAG, it.toString()) + } return params } diff --git a/easytrack/src/main/java/com/pengxr/easytrack/util/EasyTrackUtils.kt b/easytrack/src/main/java/com/pengxr/easytrack/util/EasyTrackUtils.kt index 4b1d645..8caa24e 100644 --- a/easytrack/src/main/java/com/pengxr/easytrack/util/EasyTrackUtils.kt +++ b/easytrack/src/main/java/com/pengxr/easytrack/util/EasyTrackUtils.kt @@ -270,7 +270,7 @@ var View.trackModel: ITrackModel? * Do event track, it will collect event Params around the node tree. */ @JvmOverloads -fun ComponentActivity?.trackEvent(eventName: String, params: TrackParams? = null) = +fun Activity?.trackEvent(eventName: String, params: TrackParams? = null) = findRootView(this)?.doTrackEvent(eventName, params) @JvmOverloads