Improved logging to file on uncaught exceptions

This commit is contained in:
IrPgFKS0 committed 2023-09-06 14:44:42 -07:00
1 parent 9252ff4662
commit de34ce9529
2 files changed
+25 -1

No files matched your search

+24
View File
@@ -2,5 +2,29 @@ const DayzR = require('./structures/DayzRBot');
const config = require('./config/config'); const config = require('./config/config');
const { GatewayIntentBits } = require('discord.js'); const { GatewayIntentBits } = require('discord.js');
const path = require("path");
const fs = require('fs');
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config); let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
client.build() client.build()
// Log all uncaught exceptions before killing process.
process.on('uncaughtException', async (error) => {
let d = new Date();
// Asynchronously write the error message to a log file using Promises
await new Promise((resolve, reject) => {
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth()+1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
if (logErr) {
console.error('Error writing uncaughtException to log file:', logErr);
reject(logErr);
process.exit()
} else {
resolve();
}
});
});
// Now, you can re-throw the error
process.exit()
});
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "dayzr-bot", "name": "dayzr-bot",
"version": "9.8.3", "version": "9.8.4",
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
"main": "index.js", "main": "index.js",
"nodemonConfig": { "nodemonConfig": {