From b773ad92fd9ab462e4bf77c0ba2c5566885c6e12 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 4 Aug 2020 09:58:51 +0200 Subject: [PATCH] Countly with args --- .../main/java/info/hannes/timber/DebugFormatTree.kt | 2 +- .../src/main/java/info/hannes/countly/Analytics.kt | 10 ++++++---- .../src/main/java/info/hannes/countly/IAnalytics.kt | 6 +++--- .../src/main/java/info/hannes/timber/CountlyTree.kt | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt index 14d218eb..abaf2a0d 100644 --- a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt +++ b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt @@ -17,7 +17,6 @@ open class DebugFormatTree(delegator: Class<*>? = null) : Timber.DebugTree(deleg ) } - // if there is an JSON string, try to print out pretty override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) { var localMessage = message.trim() if (localMessage.startsWith("{") && localMessage.endsWith("}")) { @@ -29,4 +28,5 @@ open class DebugFormatTree(delegator: Class<*>? = null) : Timber.DebugTree(deleg } super.logMessage(priority, tag, localMessage, t, *args) } + } diff --git a/LogcatCountlyLib/src/main/java/info/hannes/countly/Analytics.kt b/LogcatCountlyLib/src/main/java/info/hannes/countly/Analytics.kt index d5c440a4..b66bb507 100644 --- a/LogcatCountlyLib/src/main/java/info/hannes/countly/Analytics.kt +++ b/LogcatCountlyLib/src/main/java/info/hannes/countly/Analytics.kt @@ -21,13 +21,15 @@ class Analytics : IAnalytics { return countlyInstance.isInitialized } - override fun recordEvent(event: String) { + private fun toPair(vararg args: Any?) = args.map { param -> Pair(param.toString(), param.toString()) } + + override fun recordEvent(event: String, vararg args: Any?) { if (isInitialized()) { - countlyInstance.events().recordEvent(event, segmentation, 1) + countlyInstance.events().recordEvent(event, segmentation.plus(toPair(args)), 1) } } - override fun recordError(message: String) { + override fun recordError(message: String, vararg args: Any?) { if (isInitialized()) { countlyInstance.crashes().recordHandledException(RuntimeException(message)) } @@ -39,7 +41,7 @@ class Analytics : IAnalytics { } } - override fun recordWarning(message: String) { + override fun recordWarning(message: String, vararg args: Any?) { if (isInitialized()) { countlyInstance.crashes().recordHandledException(RuntimeException(message)) } diff --git a/LogcatCountlyLib/src/main/java/info/hannes/countly/IAnalytics.kt b/LogcatCountlyLib/src/main/java/info/hannes/countly/IAnalytics.kt index 80555bbc..6b0fac0d 100644 --- a/LogcatCountlyLib/src/main/java/info/hannes/countly/IAnalytics.kt +++ b/LogcatCountlyLib/src/main/java/info/hannes/countly/IAnalytics.kt @@ -6,11 +6,11 @@ interface IAnalytics { fun isInitialized(): Boolean - fun recordEvent(event: String) + fun recordEvent(event: String, vararg args: Any?) - fun recordWarning(message: String) + fun recordWarning(message: String, vararg args: Any?) - fun recordError(message: String) + fun recordError(message: String, vararg args: Any?) fun recordError(throwable: Throwable) diff --git a/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt b/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt index 7e946512..6929f92f 100644 --- a/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt +++ b/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt @@ -31,8 +31,8 @@ class CountlyTree(private val analytics: Analytics, private val serverIgnoreToke when { t != null -> analytics.recordError(t) - priority == Log.WARN -> analytics.recordEvent(localMessage) - else -> analytics.recordError(localMessage) + priority == Log.WARN -> analytics.recordEvent(localMessage, args) + else -> analytics.recordError(localMessage, args) } }