botvX_mjs/util/chatlog.mjs

18 lines
910 B
JavaScript
Raw Normal View History

2024-08-20 06:45:07 -04:00
import { appendFileSync } from "fs"
import { default as settings } from '../settings.json' with {type: "json"}
2024-08-15 05:38:09 -04:00
2024-08-20 06:45:07 -04:00
export default function (fileName, item) {
2024-08-15 05:43:42 -04:00
if (settings.disableLogging) return
const dateToday = new Date(Date.now())
const UTCYears = dateToday.getUTCFullYear()
const UTCMonths = dateToday.getUTCMonth() + 1
const UTCDays = dateToday.getUTCDate()
2024-08-15 05:43:42 -04:00
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 = `${UTCMonths}-${UTCDays}-${UTCYears}`
const logDate = `${UTCMonths}/${UTCDays}/${UTCYears} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}`
2024-08-20 06:45:07 -04:00
appendFileSync(`logs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`)
2024-08-15 05:43:42 -04:00
}