From 7f1fc42fb91785a180cb3e8a9238baa1c5d493e7 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Fri, 4 Aug 2023 10:11:08 +0200 Subject: [PATCH 1/3] Use own timber --- LogcatCoreLib/build.gradle | 2 +- .../info/hannes/timber/DebugFormatTree.kt | 4 ++-- .../info/hannes/timber/FileLoggingTree.kt | 11 ++++----- .../java/info/hannes/timber/CountlyTree.kt | 2 +- .../info/hannes/crashlytic/CrashlyticsTree.kt | 24 ++++++++++--------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/LogcatCoreLib/build.gradle b/LogcatCoreLib/build.gradle index e16f9528..03bda3b6 100644 --- a/LogcatCoreLib/build.gradle +++ b/LogcatCoreLib/build.gradle @@ -27,7 +27,7 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.1" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.7" implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7" - api "com.jakewharton.timber:timber:5.0.1" + api "com.github.hannesa2:timber:5.0.1.0" } publishing { diff --git a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt index 2f046771..cb7afd8a 100644 --- a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt +++ b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt @@ -38,7 +38,7 @@ open class DebugFormatTree(private val newLogcat: Boolean = true) : Timber.Debug } // 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("}")) { try { @@ -47,6 +47,6 @@ open class DebugFormatTree(private val newLogcat: Boolean = true) : Timber.Debug } catch (_: JSONException) { } } - super.log(priority, tag, "$method: $localMessage", t) + super.logMessage(priority, tag, "$method: $localMessage", t, args) } } diff --git a/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt b/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt index 03f5dbc3..6e8c337e 100644 --- a/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt +++ b/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt @@ -33,8 +33,7 @@ open class FileLoggingTree(externalCacheDir: File, context: Context? = null, fil init { externalCacheDir.let { if (!it.exists()) { - if (!it.mkdirs()) - Log.e(LOG_TAG, "couldn't create ${it.absoluteFile}") + if (!it.mkdirs()) Log.e(LOG_TAG, "couldn't create ${it.absoluteFile}") } val fileNameTimeStamp = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date()) file = if (context != null) { @@ -46,7 +45,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()) @@ -70,10 +69,8 @@ open class FileLoggingTree(externalCacheDir: File, context: Context? = null, fil } } - if (Thread.currentThread().name == "main") - _lastLogEntry.value = Event(textLine) - else - Handler(Looper.getMainLooper()).post { _lastLogEntry.value = Event(textLine) } + if (Thread.currentThread().name == "main") _lastLogEntry.value = Event(textLine) + else Handler(Looper.getMainLooper()).post { _lastLogEntry.value = Event(textLine) } } catch (e: Exception) { // Log to prevent an endless loop diff --git a/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt b/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt index 70180632..7e946512 100644 --- a/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt +++ b/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt @@ -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, t: 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 diff --git a/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt b/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt index bc126dac..ba761c19 100644 --- a/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt +++ b/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt @@ -8,22 +8,24 @@ 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 } - super.log(priority, tag, message, t) + super.log(priority, tag, message, t, args) - FirebaseCrashlytics.getInstance().setCustomKey("PRIORITY", when (priority) { - // 2 -> "Verbose" - // 3 -> "Debug" - 4 -> "Info" - 5 -> "Warn" - 6 -> "Error" - 7 -> "Assert" - else -> priority.toString() - }) + FirebaseCrashlytics.getInstance().setCustomKey( + "PRIORITY", when (priority) { + // 2 -> "Verbose" + // 3 -> "Debug" + 4 -> "Info" + 5 -> "Warn" + 6 -> "Error" + 7 -> "Assert" + else -> priority.toString() + } + ) tag?.let { FirebaseCrashlytics.getInstance().setCustomKey(KEY_TAG, it) } FirebaseCrashlytics.getInstance().setCustomKey(KEY_MESSAGE, message) FirebaseCrashlytics.getInstance().setCustomKey(KEY_UNIT_TEST, isRunningUnitTests.toString()) From 33128e0923f9262927c2ae73f7cdad4ee851ac66 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Wed, 5 Jun 2024 15:09:04 +0200 Subject: [PATCH 2/3] 5.0.1-delegator --- LogcatCoreLib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LogcatCoreLib/build.gradle b/LogcatCoreLib/build.gradle index 03bda3b6..70813531 100644 --- a/LogcatCoreLib/build.gradle +++ b/LogcatCoreLib/build.gradle @@ -27,7 +27,7 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.1" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.7" implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7" - api "com.github.hannesa2:timber:5.0.1.0" + api "com.github.hannesa2:timber:5.0.1-delegator" } publishing { From 9bc6e467e19e05b8bc06bb1d327e6e12b1f25e88 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Thu, 6 Jun 2024 06:32:00 +0200 Subject: [PATCH 3/3] fix --- .../java/info/hannes/timber/DebugFormatTree.kt | 17 +++++++++++++++-- .../java/info/hannes/timber/FileLoggingTree.kt | 2 +- .../main/java/info/hannes/timber/CountlyTree.kt | 2 +- .../info/hannes/crashlytic/CrashlyticsTree.kt | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt index cb7afd8a..0468aca0 100644 --- a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt +++ b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt @@ -38,7 +38,7 @@ open class DebugFormatTree(private val newLogcat: Boolean = true) : Timber.Debug } // 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?) { + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { var localMessage = message.trim() if (localMessage.startsWith("{") && localMessage.endsWith("}")) { try { @@ -47,6 +47,19 @@ open class DebugFormatTree(private val newLogcat: Boolean = true) : Timber.Debug } catch (_: JSONException) { } } - super.logMessage(priority, tag, "$method: $localMessage", t, args) + super.log(priority, tag, "$method: $localMessage", t) } + + // 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("}")) { +// try { +// val json = JSONObject(message) +// localMessage = json.toString(3) +// } catch (_: JSONException) { +// } +// } +// super.logMessage(priority, tag, "$method: $localMessage", t, args) +// } } diff --git a/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt b/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt index 6e8c337e..f2085d76 100644 --- a/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt +++ b/LogcatCoreLib/src/main/java/info/hannes/timber/FileLoggingTree.kt @@ -45,7 +45,7 @@ open class FileLoggingTree(externalCacheDir: File, context: Context? = null, fil } @SuppressLint("LogNotTimber") - override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) { + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { try { val logTimeStamp = SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS", Locale.getDefault()).format(Date()) diff --git a/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt b/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt index 7e946512..70180632 100644 --- a/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt +++ b/LogcatCountlyLib/src/main/java/info/hannes/timber/CountlyTree.kt @@ -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 logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) { + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { // we ignore INFO, DEBUG and VERBOSE if (priority <= Log.INFO) { return diff --git a/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt b/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt index ba761c19..88025365 100644 --- a/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt +++ b/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt @@ -8,12 +8,12 @@ import java.util.concurrent.atomic.AtomicBoolean @Suppress("unused") class CrashlyticsTree(private val identifier: String? = null) : Timber.Tree() { - override fun logMessage(priority: Int, tag: String?, message: String, t: Throwable?, vararg args: Any?) { + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { if (priority < Log.INFO) { return } - super.log(priority, tag, message, t, args) + super.log(priority, tag, message, t) FirebaseCrashlytics.getInstance().setCustomKey( "PRIORITY", when (priority) {