Rename log folder and move the other units of time to constants

This commit is contained in:
7cc5c4f330d47060 2024-08-15 12:50:12 -04:00
parent 9af9d8d974
commit ed02f94919
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
2 changed files with 9 additions and 6 deletions

View file

@ -5,13 +5,13 @@ const settings = require('../settings.json')
const checkLog = () => { const checkLog = () => {
if (settings.disableLogging) return if (settings.disableLogging) return
try { try {
if (!fs.readdirSync('.').includes('botvXLogs')) fs.mkdirSync('botvXLogs') if (!fs.readdirSync('.').includes('logs')) fs.mkdirSync('logs')
const dateToday = new Date(Date.now()) const dateToday = new Date(Date.now())
const dateTomorrow = new Date(Date.now() + 86400000) const dateTomorrow = new Date(Date.now() + 86400000)
const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}` const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}`
const filenameTomorrow = `${dateTomorrow.getUTCMonth() + 1}-${dateTomorrow.getUTCDate()}-${dateTomorrow.getUTCFullYear()}` const filenameTomorrow = `${dateTomorrow.getUTCMonth() + 1}-${dateTomorrow.getUTCDate()}-${dateTomorrow.getUTCFullYear()}`
if (!fs.readdirSync('./botvXLogs').includes(filenameToday)) fs.mkdirSync(`botvXLogs/${filenameToday}`) if (!fs.readdirSync('./logs').includes(filenameToday)) fs.mkdirSync(`logs/${filenameToday}`)
if (!fs.readdirSync('./botvXLogs').includes(filenameTomorrow)) fs.mkdirSync(`botvXLogs/${filenameTomorrow}`) // Create tomorrow's log directory early if (!fs.readdirSync('./logs').includes(filenameTomorrow)) fs.mkdirSync(`logs/${filenameTomorrow}`) // Create tomorrow's log directory early
} catch (e) { } catch (e) {
console.log(e) // Prevents some crashes when disk space is full or when the permissions are incorrect console.log(e) // Prevents some crashes when disk space is full or when the permissions are incorrect
} }

View file

@ -4,11 +4,14 @@ const settings = require('../settings.json')
module.exports = function (fileName, item) { module.exports = function (fileName, item) {
if (settings.disableLogging) return if (settings.disableLogging) return
const dateToday = new Date(Date.now()) const dateToday = new Date(Date.now())
const UTCYears = dateToday.getUTCFullYear()
const UTCMonths = dateToday.getUTCMonth() + 1
const UTCDays = dateToday.getUTCDate()
const UTCHours = dateToday.getUTCHours() const UTCHours = dateToday.getUTCHours()
const UTCMinutes = dateToday.getUTCMinutes().toString().padStart(2, '0') const UTCMinutes = dateToday.getUTCMinutes().toString().padStart(2, '0')
const UTCSeconds = dateToday.getUTCSeconds().toString().padStart(2, '0') const UTCSeconds = dateToday.getUTCSeconds().toString().padStart(2, '0')
const UTCMilliSeconds = dateToday.getUTCMilliseconds().toString().padStart(3, '0') const UTCMilliSeconds = dateToday.getUTCMilliseconds().toString().padStart(3, '0')
const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}` const filenameToday = `${UTCMonths}-${UTCDays}-${UTCYears}`
const logDate = `${dateToday.getUTCMonth() + 1}/${dateToday.getUTCDate()}/${dateToday.getUTCFullYear()} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}` const logDate = `${UTCMonths}/${UTCDays}/${UTCYears} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}`
fs.appendFileSync(`botvXLogs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`) fs.appendFileSync(`logs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`)
} }