From 4fae4b40b6b86806966a1f27e9f52de82bfdb6b8 Mon Sep 17 00:00:00 2001 From: aronmal Date: Wed, 5 Apr 2023 01:20:57 +0200 Subject: [PATCH] Improved logging dev experience --- leaky-ships/lib/backend/logging.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/leaky-ships/lib/backend/logging.ts b/leaky-ships/lib/backend/logging.ts index 4d38fa6..b222468 100644 --- a/leaky-ships/lib/backend/logging.ts +++ b/leaky-ships/lib/backend/logging.ts @@ -1,13 +1,20 @@ import fs from "fs" import colors, { Color } from "colors" import { NextApiRequest } from "next" -import { IncomingMessage } from "http" colors.enable() -const loggingTemplates: { [key: string]: LoggingType } = { +const loggingTemplates: { + system: LoggingType + infoGreen: LoggingType + infoCyan: LoggingType + debug: LoggingType + post: LoggingType + warn: LoggingType + error: LoggingType +} = { system: ["SYSTEM", "green"], - "info.green": ["INFO", "green"], - "info.cyan": ["INFO", "cyan"], + infoGreen: ["INFO", "green"], + infoCyan: ["INFO", "cyan"], debug: ["Debug", "grey"], post: ["Post", "white"], warn: ["WARN", "yellow"], @@ -22,7 +29,7 @@ let started: boolean = false async function logStartup() { await fs.promises.stat("log").catch(async () => { await fs.promises.mkdir("log") - await logging(`Created 'log' Folder.`, ["info.cyan", "system"]) + await logging(`Created 'log' Folder.`, ["infoCyan", "system"]) }) started = true }