Skip to content

Commit

Permalink
Fixed a bug in the log file generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed Mar 18, 2022
1 parent cfad8f9 commit 1c3574f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
8 changes: 6 additions & 2 deletions source/events/client/debug.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { createWriteStream } = require("fs");
const { createWriteStream, existsSync, mkdirSync } = require("fs");
const { format } = require("util");

module.exports = (info) => {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDay();
const file = createWriteStream(__dirname + "../../../logs/debug_" + year + "-" + month + "-" + day + ".log", { "flags" : "w" });
const dir = "./source/logs/";

if (!existsSync(dir)) mkdirSync(dir);

const file = createWriteStream("./source/logs/debug_" + year + "-" + month + "-" + day + ".log", { "flags" : "w" });

file.write(format(info) + "\n");
};
10 changes: 6 additions & 4 deletions source/events/client/error.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const { createWriteStream } = require("fs");
const { createWriteStream, existsSync, mkdirSync } = require("fs");
const { format } = require("util");

module.exports = (error) => {
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDay();
const file = createWriteStream(__dirname + "../../../logs/error_" + year + "-" + month + "-" + day + "_" + hours + "-" + minutes + ".log", { "flags" : "w" });
const dir = "./source/logs/";

if (!existsSync(dir)) mkdirSync(dir);

const file = createWriteStream("./source/logs/error_" + year + "-" + month + "-" + day + ".log", { "flags" : "w" });

file.write(format(error) + "\n");
};
10 changes: 6 additions & 4 deletions source/events/client/warn.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const { createWriteStream } = require("fs");
const { createWriteStream, existsSync, mkdirSync } = require("fs");
const { format } = require("util");

module.exports = (info) => {
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDay();
const file = createWriteStream(__dirname + "../../../logs/warn_" + year + "-" + month + "-" + day + "_" + hours + "-" + minutes + ".log", { "flags" : "w" });
const dir = "./source/logs/";

if (!existsSync(dir)) mkdirSync(dir);

const file = createWriteStream("./source/logs/warn_" + year + "-" + month + "-" + day + ".log", { "flags" : "w" });

file.write(format(info) + "\n");
};
22 changes: 17 additions & 5 deletions source/handlers/process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const discord = require("discord.js");
const packages = require("../../package.json");
const { createWriteStream } = require("fs");
const { createWriteStream, existsSync, mkdirSync } = require("fs");
const { format } = require("util");

module.exports = (client) => {
Expand All @@ -25,7 +25,11 @@ module.exports = (client) => {
};

process.on("unhandledRejection", (reason, promise) => {
const file = createWriteStream(__dirname + "../../logs/process" + logDateTime(new Date()) + ".log", { "flags" : "w" });
const dir = "./source/logs/";

if (!existsSync(dir)) mkdirSync(dir);

const file = createWriteStream("./source/logs/process" + logDateTime(new Date()) + ".log", { "flags" : "w" });

console.group(consoleDateTime(new Date()) + " :: \u001b[41;1mUnhandled Rejection/Catch\u001b[0m");
console.group("\u001b[1mFull Error:\u001b[0m ");
Expand All @@ -38,12 +42,16 @@ module.exports = (client) => {
console.info("\u001b[1mDiscord.js:\u001b[0m v" + discord.version);
console.info("\u001b[1mNode.js:\u001b[0m " + process.version);
console.groupEnd();

file.write(format(reason, promise) + "\n");
});

process.on("uncaughtException", (err, origin) => {
const file = createWriteStream(__dirname + "../../logs/" + year + "-" + month + "-" + day + "-process.log", { "flags" : "w" });
const dir = "./source/logs/";

if (!existsSync(dir)) mkdirSync(dir);

const file = createWriteStream("./source/logs/process" + logDateTime(new Date()) + ".log", { "flags" : "w" });

console.group(consoleDateTime(new Date()) + " :: \u001b[41;1mUncaught Exception/Catch\u001b[0m");
console.group("\u001b[1mFull Error:\u001b[0m ");
Expand All @@ -61,7 +69,11 @@ module.exports = (client) => {
});

process.on("multipleResolves", (type, promise, reason) => {
const file = createWriteStream(__dirname + "../../logs/" + year + "-" + month + "-" + day + "-process.log", { "flags" : "w" });
const dir = "./source/logs/";

if (!existsSync(dir)) mkdirSync(dir);

const file = createWriteStream("./source/logs/process" + logDateTime(new Date()) + ".log", { "flags" : "w" });

switch (reason.toLocaleString()) {
case "":
Expand Down

0 comments on commit 1c3574f

Please sign in to comment.