Skip to content

Commit

Permalink
Countly with args
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Dec 11, 2020
1 parent 8878044 commit 97ef98b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LogcatCoreLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
api 'com.google.android.material:material:1.2.1'
api 'com.jakewharton.timber:timber:4.7.1'
api 'com.github.hannesa2:Timber:4.7.1.0'
}
6 changes: 3 additions & 3 deletions LogcatCoreLib/src/main/java/info/hannes/timber/DebugTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ open class DebugTree : Timber.DebugTree() {
)
}

// if there is an JSON string, try to print out pretty
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) {
var localMessage = message.trim()
if (localMessage.startsWith("{") && localMessage.endsWith("}")) {
val json = JSONObject(message)
Expand All @@ -27,6 +26,7 @@ open class DebugTree : Timber.DebugTree() {
} catch (e: JSONException) {
}
}
super.log(priority, tag, localMessage, t)
super.logMessage(priority, tag, localMessage, t, *args)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class FileLoggingTree(externalCacheDir: File, context: Context? = null, fil
}

@SuppressLint("LogNotTimber")
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) {
try {
val logTimeStamp = SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS", Locale.getDefault()).format(Date())

Expand Down
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 @@ -19,7 +19,7 @@ class CountlyTree(private val analytics: Analytics, private val serverIgnoreToke
private val t = serverIgnoreToken
private val regex: Regex = "$t.+?$t|$t[^$t]*$".toRegex()

override fun log(priority: Int, tag: String?, message: String, throwable: Throwable?) {
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
Expand All @@ -30,9 +30,9 @@ class CountlyTree(private val analytics: Analytics, private val serverIgnoreToke
}

when {
throwable != null -> analytics.recordError(throwable)
priority == Log.WARN -> analytics.recordEvent(localMessage)
else -> analytics.recordError(localMessage)
t != null -> analytics.recordError(t)
priority == Log.WARN -> analytics.recordEvent(localMessage, args)
else -> analytics.recordError(localMessage, args)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicBoolean
@Suppress("unused")
class CrashlyticsTree(private val identifier: String? = null) : Timber.Tree() {

override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) {
if (priority < Log.INFO) {
return
}
Expand Down

0 comments on commit 97ef98b

Please sign in to comment.