import log4js from "logger"; const logger = log4js.getLogger("ERROR"); const processHandlersKey = "__personPanelErrorLoggerProcessHandlers"; function installProcessErrorLogging() { const g = globalThis as typeof globalThis & { [processHandlersKey]?: boolean }; if (g[processHandlersKey]) return; g[processHandlersKey] = true; process.on("unhandledRejection", (reason) => { if (reason instanceof Error) { logger.error("[unhandledRejection]", reason.message, reason.stack ?? ""); } else { logger.error("[unhandledRejection]", String(reason)); } }); process.on("uncaughtException", (err) => { logger.error("[uncaughtException]", err.message, err.stack ?? ""); }); } if (import.meta.dev) { console.log("plugin: 03.error-logger"); } export default defineNitroPlugin((nitroApp) => { installProcessErrorLogging(); nitroApp.hooks.hook("error", (error, context) => { const event = context.event; const tags = Array.isArray(context.tags) ? (context.tags as string[]).join(",") : ""; logger.error( event?.method ?? "", event?.path ?? "(no request)", tags ? `[${tags}]` : "", error.message, error.stack ?? "" ); }); });