Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const process = require("node:process");
- let errorData = [];
- //JSON Error log
- try {
- const errorLog = fs.readFileSync('errorLog.json', 'utf-8');
- errorData = JSON.parse(errorLog)
- } catch (error) {
- console.log(error)
- }
- //Unhandled Rejections
- process.on('unhandledRejection', async (reason, promise) => {
- const logEntry = {
- timestamp: new Date().toISOString(),
- type: "Unhandled Rejection",
- promise: `${promise}`,
- reason: `${reason}`,
- }
- errorData.push(logEntry)
- });
- //Uncaught Exception
- process.on('uncaughtException', (err) => {
- const logEntry = {
- timestamp: new Date().toISOString(),
- type: "Uncaugt Exception",
- error: `${err}`
- }
- errorData.push(logEntry)
- });
- //Uncaught Exception Monitor
- process.on('uncaughtExceptionMonitor', (err, origin) => {
- const logEntry = {
- timestamp: new Date().toISOString(),
- type: "Uncaught Exception Monitor",
- error: `${err}}`,
- origin: `${origin}`,
- }
- errorData.push(logEntry)
- });
Advertisement
Add Comment
Please, Sign In to add comment