ExtensionLogger.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/extensions/ExtensionLogger.kt
1package eu.friedcutlet.yokan.services.extensions23import eu.friedcutlet.yokan.services.logging.AppLogger4import eu.friedcutlet.yokan.services.notifications.InAppNotifications56/**7 * Logger for extension execution. JS `console.log/warn/error` calls flow8 * through here via the `log` bridge channel, as do caught extension9 * exceptions at the call boundary. Output goes through [LogSink] — stdout10 * always, plus the opt-in log file.11 */12object ExtensionLogger {1314 fun log(sourceName: String, message: String) {15 AppLogger.info("[ext $sourceName] $message")16 }1718 /**19 * Records that calling [action] on the given source's runtime threw. The20 * caller is expected to be inside a `runCatching { ... }.getOrElse { ... }`21 * or equivalent fallback — this method only logs, it does not rethrow.22 */23 fun error(sourceName: String, action: String, throwable: Throwable) {24 val cause = throwable.message.orEmpty()25 .lineSequence()26 .firstOrNull()27 .orEmpty()28 .ifBlank { throwable::class.simpleName.orEmpty() }29 AppLogger.error("[ext $sourceName] $action failed: $cause")30 InAppNotifications.post(31 title = "$sourceName error",32 message = "$action failed: $cause",33 )34 throwable.printStackTrace()35 }36}37