Rename log folder and move the other units of time to constants
This commit is contained in:
parent
9af9d8d974
commit
ed02f94919
2 changed files with 9 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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`)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue