File size: 817 Bytes
813eca2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import logger from './logger.js';
// 允许无限量的监听器
process.setMaxListeners(Infinity);
// 输出未捕获异常
process.on("uncaughtException", (err, origin) => {
logger.error(`An unhandled error occurred: ${origin}`, err);
});
// 输出未处理的Promise.reject
process.on("unhandledRejection", (_, promise) => {
promise.catch(err => logger.error("An unhandled rejection occurred:", err));
});
// 输出系统警告信息
process.on("warning", warning => logger.warn("System warning: ", warning));
// 进程退出监听
process.on("exit", () => {
logger.info("Service exit");
logger.footer();
});
// 进程被kill
process.on("SIGTERM", () => {
logger.warn("received kill signal");
process.exit(2);
});
// Ctrl-C进程退出
process.on("SIGINT", () => {
process.exit(0);
}); |