Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LogcatCoreLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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-delegator"
}

publishing {
Expand Down
13 changes: 13 additions & 0 deletions LogcatCoreLib/src/main/java/info/hannes/timber/DebugFormatTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading