package eu.friedcutlet.yokan.services.extensions import eu.friedcutlet.yokan.services.logging.AppLogger import eu.friedcutlet.yokan.services.notifications.InAppNotifications /** * Logger for extension execution. JS `console.log/warn/error` calls flow * through here via the `log` bridge channel, as do caught extension * exceptions at the call boundary. Output goes through [LogSink] — stdout * always, plus the opt-in log file. */ object ExtensionLogger { fun log(sourceName: String, message: String) { AppLogger.info("[ext $sourceName] $message") } /** * Records that calling [action] on the given source's runtime threw. The * caller is expected to be inside a `runCatching { ... }.getOrElse { ... }` * or equivalent fallback — this method only logs, it does not rethrow. */ fun error(sourceName: String, action: String, throwable: Throwable) { val cause = throwable.message.orEmpty() .lineSequence() .firstOrNull() .orEmpty() .ifBlank { throwable::class.simpleName.orEmpty() } AppLogger.error("[ext $sourceName] $action failed: $cause") InAppNotifications.post( title = "$sourceName error", message = "$action failed: $cause", ) throwable.printStackTrace() } }