|
1 | 1 | import type { HandleClientError } from "@sveltejs/kit"; |
| 2 | +import { info, warn, error as logError, debug, trace } from "@tauri-apps/plugin-log"; |
| 3 | + |
| 4 | +// Forward JS console logs to the Tauri native log plugin. |
| 5 | +// On Android this routes to logcat. Requires "log:default" in capabilities/main.json. |
| 6 | +function patchConsoleForLogcat() { |
| 7 | + const _log = console.log.bind(console); |
| 8 | + const _warn = console.warn.bind(console); |
| 9 | + const _error = console.error.bind(console); |
| 10 | + const _debug = console.debug.bind(console); |
| 11 | + |
| 12 | + const stringify = (...args: unknown[]) => |
| 13 | + args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" "); |
| 14 | + |
| 15 | + console.log = (...args: unknown[]) => { |
| 16 | + _log(...args); |
| 17 | + info(stringify(...args)).catch(() => {}); |
| 18 | + }; |
| 19 | + console.warn = (...args: unknown[]) => { |
| 20 | + _warn(...args); |
| 21 | + warn(stringify(...args)).catch(() => {}); |
| 22 | + }; |
| 23 | + console.error = (...args: unknown[]) => { |
| 24 | + _error(...args); |
| 25 | + logError(stringify(...args)).catch(() => {}); |
| 26 | + }; |
| 27 | + console.debug = (...args: unknown[]) => { |
| 28 | + _debug(...args); |
| 29 | + debug(stringify(...args)).catch(() => {}); |
| 30 | + }; |
| 31 | + |
| 32 | + // Emit a test log immediately so we can confirm the bridge works |
| 33 | + info("[VollaMessages:Boot] JS→logcat bridge active").catch(() => {}); |
| 34 | +} |
| 35 | + |
| 36 | +try { |
| 37 | + patchConsoleForLogcat(); |
| 38 | +} catch { |
| 39 | + // Not in a Tauri context — ignore silently. |
| 40 | +} |
2 | 41 |
|
3 | 42 | export const handleError: HandleClientError = async ({ error, event, status, message }) => { |
4 | 43 | const errorId = crypto.randomUUID(); |
|
0 commit comments