From 49360a7c5b92c7275beb952b3ea8447caf8aaf06 Mon Sep 17 00:00:00 2001 From: James Shiffer Date: Sun, 8 Oct 2023 19:15:00 -0700 Subject: [PATCH] Better date formatting in logs --- discord/bot.ts | 2 +- discord/util.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/discord/bot.ts b/discord/bot.ts index 983f4d4..e7a199f 100644 --- a/discord/bot.ts +++ b/discord/bot.ts @@ -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); } diff --git a/discord/util.ts b/discord/util.ts index 16d1388..f791d17 100644 --- a/discord/util.ts +++ b/discord/util.ts @@ -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() {