toowake

index.js

Sep 4th, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const process = require("node:process");
  3.  
  4. let errorData = [];
  5. //JSON Error log
  6. try {
  7.     const errorLog = fs.readFileSync('errorLog.json', 'utf-8');
  8.     errorData = JSON.parse(errorLog)
  9. } catch (error) {
  10.     console.log(error)
  11. }
  12.  
  13. //Unhandled Rejections
  14. process.on('unhandledRejection', async (reason, promise) => {
  15.     const logEntry = {
  16.         timestamp: new Date().toISOString(),
  17.         type: "Unhandled Rejection",
  18.         promise: `${promise}`,
  19.         reason: `${reason}`,
  20.     }
  21.  
  22.     errorData.push(logEntry)
  23. });
  24.  
  25. //Uncaught Exception
  26. process.on('uncaughtException', (err) => {
  27.         const logEntry = {
  28.             timestamp: new Date().toISOString(),
  29.             type: "Uncaugt Exception",
  30.             error: `${err}`
  31.         }
  32.         errorData.push(logEntry)
  33. });
  34.  
  35. //Uncaught Exception Monitor
  36. process.on('uncaughtExceptionMonitor', (err, origin) => {
  37.     const logEntry = {
  38.         timestamp: new Date().toISOString(),
  39.         type: "Uncaught Exception Monitor",
  40.         error: `${err}}`,
  41.         origin: `${origin}`,
  42.     }
  43.  
  44.     errorData.push(logEntry)
  45. });
Advertisement
Add Comment
Please, Sign In to add comment