From 166d1c59a50fb1cac6639b736229f44a6c3ce022 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 15 Sep 2024 13:47:26 +0200 Subject: [PATCH] refactor: :fire: Remove some code already provided by LogTape --- utils/loggers.ts | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/utils/loggers.ts b/utils/loggers.ts index c4377f8d..9139d2d7 100644 --- a/utils/loggers.ts +++ b/utils/loggers.ts @@ -13,11 +13,11 @@ import { type RotatingFileSinkOptions, type Sink, configure, + defaultTextFormatter, getConsoleSink, getLevelFilter, } from "@logtape/logtape"; import chalk from "chalk"; -import stripAnsi from "strip-ansi"; import { config } from "~/packages/config-manager"; // HACK: This is a workaround for the lack of type exports in the Logtape package. @@ -74,34 +74,6 @@ const levelAbbreviations: Record = { fatal: "FTL", }; -export function defaultTextFormatter(record: LogRecord): string { - const ts = new Date(record.timestamp); - let msg = ""; - for (let i = 0; i < record.message.length; i++) { - if (i % 2 === 0) { - msg += record.message[i]; - } else { - msg += Bun.inspect(stripAnsi(record.message[i] as string)).match( - /"(.*?)"/, - )?.[1]; - } - } - const category = record.category.join("\xb7"); - return `${ts.toISOString().replace("T", " ").replace("Z", " +00:00")} [${ - levelAbbreviations[record.level] - }] ${category}: ${msg}\n`; -} - -/** - * A console formatter is a function that accepts a log record and returns - * an array of arguments to pass to {@link console.log}. - * - * @param record The log record to format. - * @returns The formatted log record, as an array of arguments for - * {@link console.log}. - */ -export type ConsoleFormatter = (record: LogRecord) => readonly unknown[]; - /** * The styles for the log level in the console. */