feat: add throwable support to Log.d/i and inline lambda overloads
- Add optional throwable parameter to d() and i() across all platforms - Add inline lambda overloads for all log levels to defer message construction, avoiding string allocation when level is filtered - Restore VoiceMessagePreview to pass throwable directly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
+12
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user