Skip to content

Commit

Permalink
Countly with args
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jun 12, 2022
1 parent e9241cd commit b773ad9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("}")) {
Expand All @@ -29,4 +28,5 @@ open class DebugFormatTree(delegator: Class<*>? = null) : Timber.DebugTree(deleg
}
super.logMessage(priority, tag, localMessage, t, *args)
}

}
10 changes: 6 additions & 4 deletions LogcatCountlyLib/src/main/java/info/hannes/countly/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit b773ad9

Please sign in to comment.