From d4df7b1417fe979c707b75eb18166b8a8b728b62 Mon Sep 17 00:00:00 2001 From: Histmy Date: Tue, 13 May 2025 14:42:10 +0200 Subject: [PATCH] =?UTF-8?q?Potun=C4=9Bn=C3=AD=20utils=20funkce=20`log`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/utils.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5971bf4..58d8688 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -90,15 +90,26 @@ export function adminLog(client: Client, text: string, err?: string | Error) { } export function log(...content: unknown[]) { - let jeChyba = false; + let hasError = false; - const jo = content.map(h => { - if (h instanceof Error) return `\x1b[31m${h.stack || h}\x1b[0m`; - return h; + const colored = content.map(entry => { + if (entry instanceof Error) { + hasError = true; + return `\x1b[31m${entry.stack || entry}\x1b[0m`; + } + + return entry; }); const d = new Date(); - console.log(`[${d.getDate()}.${d.getMonth() + 1}. ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}]:`, ...jo); + + const params = [`[${d.getDate()}.${d.getMonth() + 1}. ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}]:`, ...colored]; + + if (hasError) { + console.error(...params); + } else { + console.log(...params); + } } export async function sendDM(user: User, txt: string) {