diff --git a/LogcatCoreLib/build.gradle b/LogcatCoreLib/build.gradle index 4251a971..230d527b 100644 --- a/LogcatCoreLib/build.gradle +++ b/LogcatCoreLib/build.gradle @@ -24,7 +24,7 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.1" implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.1' - api 'com.jakewharton.timber:timber:5.0.1' + api 'com.github.hannesa2:timber:5.0.1-delegator' } 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..0468aca0 100644 --- a/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt +++ b/LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt @@ -49,4 +49,17 @@ open class DebugFormatTree(private val newLogcat: Boolean = true) : Timber.Debug } 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 03f5dbc3..f2085d76 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) { @@ -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/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt b/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt index bc126dac..88025365 100644 --- a/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt +++ b/LogcatCrashlyticLib/src/main/java/info/hannes/crashlytic/CrashlyticsTree.kt @@ -15,15 +15,17 @@ class CrashlyticsTree(private val identifier: String? = null) : Timber.Tree() { super.log(priority, tag, message, t) - 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())