refactor: better logs

This commit is contained in:
zhom committed 2026-10-10 01:11:04 +04:00
1 parent 2604994507
commit bf625fac2c
91 files changed
+4353 -3239

No files matched your search

+21 -1
View File
@@ -1,12 +1,32 @@
import { attachConsole } from "@tauri-apps/plugin-log";
import { attachConsole, error as logError } from "@tauri-apps/plugin-log";
let consoleAttached = false;
let errorsForwarded = false;
function describe(reason: unknown): string {
if (reason instanceof Error) return reason.stack ?? reason.message;
return typeof reason === "string" ? reason : JSON.stringify(reason);
}
export async function setupLogging() {
if (consoleAttached) {
return;
}
// Only uncaught failures go to the log file. Forwarding console.error too
// would loop: attachConsole writes every backend line back to the console.
if (!errorsForwarded) {
errorsForwarded = true;
window.addEventListener("error", (event) => {
void logError(
`Uncaught error err="${describe(event.error ?? event.message)}" source=${event.filename}:${event.lineno}:${event.colno}`,
);
});
window.addEventListener("unhandledrejection", (event) => {
void logError(`Unhandled rejection err="${describe(event.reason)}"`);
});
}
try {
await attachConsole();
consoleAttached = true;