diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/uploads/VoiceMessagePreview.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/uploads/VoiceMessagePreview.kt index 7603e0864..43bb07f54 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/uploads/VoiceMessagePreview.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/uploads/VoiceMessagePreview.kt @@ -275,7 +275,7 @@ private fun ManageMediaPlayer( try { player?.stop() } catch (e: IllegalStateException) { - Log.d("VoiceMessagePreview", "MediaPlayer stop failed (already stopped): ${e.message}") + Log.d("VoiceMessagePreview", "MediaPlayer stop failed (already stopped)", e) } player?.release() onPlayerChanged(null) diff --git a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.android.kt b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.android.kt index 215191ba0..6f9bf5ac6 100644 --- a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.android.kt +++ b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.android.kt @@ -48,14 +48,24 @@ actual object PlatformLog { actual fun d( tag: String, message: String, + throwable: Throwable?, ) { - android.util.Log.d(tag, message) + if (throwable != null) { + android.util.Log.d(tag, message, throwable) + } else { + android.util.Log.d(tag, message) + } } actual fun i( tag: String, message: String, + throwable: Throwable?, ) { - android.util.Log.i(tag, message) + if (throwable != null) { + android.util.Log.i(tag, message, throwable) + } else { + android.util.Log.i(tag, message) + } } } diff --git a/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt b/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt index 299931efb..882c298c6 100644 --- a/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt +++ b/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt @@ -50,14 +50,24 @@ actual object PlatformLog { actual fun d( tag: String, message: String, + throwable: Throwable?, ) { - NSLog("DEBUG: [$tag] $message") + if (throwable != null) { + NSLog("DEBUG: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") + } else { + NSLog("DEBUG: [$tag] $message") + } } actual fun i( tag: String, message: String, + throwable: Throwable?, ) { - NSLog("INFO: [$tag] $message") + if (throwable != null) { + NSLog("INFO: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") + } else { + NSLog("INFO: [$tag] $message") + } } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/Log.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/Log.kt index b489ccfd5..e2ecd1a5f 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/Log.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/Log.kt @@ -26,15 +26,31 @@ object Log { fun d( tag: String, message: String, + throwable: Throwable? = null, ) { - if (minLevel <= LogLevel.DEBUG) PlatformLog.d(tag, message) + if (minLevel <= LogLevel.DEBUG) PlatformLog.d(tag, message, throwable) + } + + inline fun d( + tag: String, + message: () -> String, + ) { + if (minLevel <= LogLevel.DEBUG) PlatformLog.d(tag, message()) } fun i( tag: String, message: String, + throwable: Throwable? = null, ) { - if (minLevel <= LogLevel.INFO) PlatformLog.i(tag, message) + if (minLevel <= LogLevel.INFO) PlatformLog.i(tag, message, throwable) + } + + inline fun i( + tag: String, + message: () -> String, + ) { + if (minLevel <= LogLevel.INFO) PlatformLog.i(tag, message()) } fun w( @@ -45,6 +61,13 @@ object Log { if (minLevel <= LogLevel.WARN) PlatformLog.w(tag, message, throwable) } + inline fun w( + tag: String, + message: () -> String, + ) { + if (minLevel <= LogLevel.WARN) PlatformLog.w(tag, message()) + } + fun e( tag: String, message: String, @@ -52,4 +75,11 @@ object Log { ) { if (minLevel <= LogLevel.ERROR) PlatformLog.e(tag, message, throwable) } + + inline fun e( + tag: String, + message: () -> String, + ) { + if (minLevel <= LogLevel.ERROR) PlatformLog.e(tag, message()) + } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.kt index ecc325422..bf248e241 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.kt @@ -36,10 +36,12 @@ expect object PlatformLog { fun d( tag: String, message: String, + throwable: Throwable? = null, ) fun i( tag: String, message: String, + throwable: Throwable? = null, ) } diff --git a/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt b/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt index 65ac883f6..33a737a66 100644 --- a/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt +++ b/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt @@ -56,14 +56,24 @@ actual object PlatformLog { actual fun d( tag: String, message: String, + throwable: Throwable?, ) { - println("${time()} DEBUG: [$tag] $message") + if (throwable != null) { + println("${time()} DEBUG: [$tag] $message. Throwable: ${throwable.message}") + } else { + println("${time()} DEBUG: [$tag] $message") + } } actual fun i( tag: String, message: String, + throwable: Throwable?, ) { - println("${time()} INFO : [$tag] $message") + if (throwable != null) { + println("${time()} INFO : [$tag] $message. Throwable: ${throwable.message}") + } else { + println("${time()} INFO : [$tag] $message") + } } }