You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
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}]` : "",
|
|
"\n",
|
|
error
|
|
);
|
|
});
|
|
});
|
|
|