Better date formatting in logs

This commit is contained in:
James Shiffer 2023-10-08 19:15:00 -07:00
parent 2809c29c9a
commit 49360a7c5b
2 changed files with 8 additions and 4 deletions

View File

@ -86,7 +86,7 @@ async function scheduleRandomMessage(firstTime = false)
const timeoutMins = Math.random() * 360 + 120;
const scheduledTime = new Date();
scheduledTime.setMinutes(scheduledTime.getMinutes() + timeoutMins);
logInfo(`[bot] Next MOTD: ${scheduledTime}`);
logInfo(`[bot] Next MOTD: ${scheduledTime.toLocaleTimeString()}`);
setTimeout(scheduleRandomMessage, timeoutMins * 60 * 1000);
}

View File

@ -16,16 +16,20 @@ const reactionEmojis: string[] = process.env.REACTIONS.split(',');
let db: Database = null;
function curDateStr() {
return new Date().toJSON().replace('T', ' ').replace('Z', '');
}
function logInfo(...data) {
console.log(`[${new Date()}] ${data.join(' ')}`);
console.log(`[${curDateStr()}] ${data.join(' ')}`);
}
function logWarn(...data) {
console.warn(`[${new Date()}] ${data.join(' ')}`);
console.warn(`[${curDateStr()}] ${data.join(' ')}`);
}
function logError(...data) {
console.error(`[${new Date()}] ${data.join(' ')}`);
console.error(`[${curDateStr()}] ${data.join(' ')}`);
}
async function openDb() {