From ed02f94919bd41be54cd571344ee956c018585c1 Mon Sep 17 00:00:00 2001 From: 7cc5c4f330d47060 Date: Thu, 15 Aug 2024 12:50:12 -0400 Subject: [PATCH] Rename log folder and move the other units of time to constants --- plugins/chatlog.js | 6 +++--- util/chatlog.js | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/chatlog.js b/plugins/chatlog.js index 1676681..8f432a3 100755 --- a/plugins/chatlog.js +++ b/plugins/chatlog.js @@ -5,13 +5,13 @@ const settings = require('../settings.json') const checkLog = () => { if (settings.disableLogging) return try { - if (!fs.readdirSync('.').includes('botvXLogs')) fs.mkdirSync('botvXLogs') + if (!fs.readdirSync('.').includes('logs')) fs.mkdirSync('logs') const dateToday = new Date(Date.now()) const dateTomorrow = new Date(Date.now() + 86400000) const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}` const filenameTomorrow = `${dateTomorrow.getUTCMonth() + 1}-${dateTomorrow.getUTCDate()}-${dateTomorrow.getUTCFullYear()}` - if (!fs.readdirSync('./botvXLogs').includes(filenameToday)) fs.mkdirSync(`botvXLogs/${filenameToday}`) - if (!fs.readdirSync('./botvXLogs').includes(filenameTomorrow)) fs.mkdirSync(`botvXLogs/${filenameTomorrow}`) // Create tomorrow's log directory early + if (!fs.readdirSync('./logs').includes(filenameToday)) fs.mkdirSync(`logs/${filenameToday}`) + if (!fs.readdirSync('./logs').includes(filenameTomorrow)) fs.mkdirSync(`logs/${filenameTomorrow}`) // Create tomorrow's log directory early } catch (e) { console.log(e) // Prevents some crashes when disk space is full or when the permissions are incorrect } diff --git a/util/chatlog.js b/util/chatlog.js index 951cb77..4e8c602 100644 --- a/util/chatlog.js +++ b/util/chatlog.js @@ -4,11 +4,14 @@ const settings = require('../settings.json') module.exports = function (fileName, item) { if (settings.disableLogging) return const dateToday = new Date(Date.now()) + const UTCYears = dateToday.getUTCFullYear() + const UTCMonths = dateToday.getUTCMonth() + 1 + const UTCDays = dateToday.getUTCDate() const UTCHours = dateToday.getUTCHours() const UTCMinutes = dateToday.getUTCMinutes().toString().padStart(2, '0') const UTCSeconds = dateToday.getUTCSeconds().toString().padStart(2, '0') const UTCMilliSeconds = dateToday.getUTCMilliseconds().toString().padStart(3, '0') - const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}` - const logDate = `${dateToday.getUTCMonth() + 1}/${dateToday.getUTCDate()}/${dateToday.getUTCFullYear()} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}` - fs.appendFileSync(`botvXLogs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`) + const filenameToday = `${UTCMonths}-${UTCDays}-${UTCYears}` + const logDate = `${UTCMonths}/${UTCDays}/${UTCYears} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}` + fs.appendFileSync(`logs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`) }