diff --git a/discord-bot-core/.gitrepo b/discord-bot-core/.gitrepo index 6008774..9de494b 100644 --- a/discord-bot-core/.gitrepo +++ b/discord-bot-core/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = git@github.com:benji7425/discord-bot-core.git branch = master - commit = 8efb033b8f7f421677f7ddb1aa3cc7801202bd54 - parent = ba6caa6be5cd775f794246736e1395ed7fa9f979 + commit = 5fd4a4323c96a7c75fef5cbe80c36ab02cf83c57 + parent = 68f565c65c702462b84b0c2abc22711db92c3821 method = merge cmdver = 0.3.1 diff --git a/discord-bot-core/Client.js b/discord-bot-core/Client.js index da8b2e2..589f87a 100644 --- a/discord-bot-core/Client.js +++ b/discord-bot-core/Client.js @@ -56,7 +56,7 @@ module.exports = class Client extends Discord.Client { onDebug(info) { if (!InternalConfig.debugIgnores.some(x => info.startsWith(x))) - CoreUtil.dateLog(info); + CoreUtil.dateDebug(info); } onUnhandledException(client, err) { diff --git a/discord-bot-core/Util.js b/discord-bot-core/Util.js index 9240244..7055e10 100644 --- a/discord-bot-core/Util.js +++ b/discord-bot-core/Util.js @@ -1,7 +1,8 @@ const Console = require("console"); const SimpleFileWriter = require("simple-file-writer"); -const logWriter = new SimpleFileWriter("./log"); +const logWriter = new SimpleFileWriter("./console.log"); +const debugLogWriter = new SimpleFileWriter("./debug.log"); /** * Returns a promise that the user will answer @@ -27,23 +28,40 @@ function ask(client, textChannel, member, question) { } function dateLog(...args) { - args = formatArgs(args); - Console.log.apply(this, args); - logWriter.write(args.join("") + "\n"); + doDateLog(Console.log, logWriter, args); } function dateError(...args) { + doDateLog(Console.error, logWriter, args); +} + +function dateDebug(...args) { + doDateLog(null, null, args); +} + +function doDateLog(consoleMethod, fileWriter, args) { args = formatArgs(args); - Console.error.apply(this, args); - logWriter.write(args.join("") + "\n"); + + if (consoleMethod !== null) + consoleMethod.apply(this, args); + + if (fileWriter !== null) + fileWriter.write(formatArgsForFile(args)); + + debugLogWriter.write(formatArgsForFile(args)); } function formatArgs(args) { return ["[", new Date().toUTCString(), "] "].concat(args); } +function formatArgsForFile(args) { + return args.join("") + "\n"; +} + module.exports = { dateError, dateLog, + dateDebug, ask }; \ No newline at end of file