From e66da0d3f08a0c3015fbb40274f4f0c4bf20fc64 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sun, 7 Apr 2024 20:33:03 +0100 Subject: [PATCH] feat: begin legwork on improving logging i.e. stripping out all this app-specific stuff we're using journald as our choke point like normal people... --- bot/package.json | 3 ++- bot/src/config.ts | 8 -------- bot/src/utils/logger.ts | 39 +++------------------------------------ pnpm-lock.yaml | 2 ++ 4 files changed, 7 insertions(+), 45 deletions(-) diff --git a/bot/package.json b/bot/package.json index 95b7637b3..c3d2a1aff 100644 --- a/bot/package.json +++ b/bot/package.json @@ -42,7 +42,8 @@ "tachi-common": "workspace:../common", "ts-node": "10.9.1", "tsconfig-paths": "3.12.0", - "typescript": "4.9.4" + "typescript": "4.9.4", + "winston": "3.5.1" }, "engines": { "node": "16", diff --git a/bot/src/config.ts b/bot/src/config.ts index ab18c2fbb..2300ed974 100644 --- a/bot/src/config.ts +++ b/bot/src/config.ts @@ -38,9 +38,6 @@ export interface BotConfig { LIMBO_CHANNEL?: string; APPROVED_ROLE?: string; }; - LOGGER?: { - SEQ_API_KEY?: string; - }; } function ParseBotConfig(fileLoc = "conf.json5"): BotConfig { @@ -95,9 +92,6 @@ function ParseBotConfig(fileLoc = "conf.json5"): BotConfig { LIMBO_CHANNEL: "*string", }, - LOGGER: p.optional({ - SEQ_API_KEY: "*string", - }), }); if (err) { @@ -113,7 +107,6 @@ export interface ProcessEnvironment { nodeEnv: "dev" | "production" | "staging" | "test"; mongoUrl: string; port: integer; - seqUrl?: string; } function ParseEnvVars() { @@ -146,7 +139,6 @@ function ParseEnvVars() { nodeEnv: process.env.NODE_ENV, mongoUrl: process.env.MONGO_URL, port: Number(process.env.PORT), - seqUrl: process.env.SEQ_URL, } as ProcessEnvironment; } diff --git a/bot/src/utils/logger.ts b/bot/src/utils/logger.ts index ab014f0e7..c30cd4a0c 100644 --- a/bot/src/utils/logger.ts +++ b/bot/src/utils/logger.ts @@ -1,44 +1,11 @@ -import { Transport as SeqTransport } from "@valuabletouch/winston-seq"; -import { BotConfig, ProcessEnv } from "config"; import { CreateLogger } from "mei-logger"; +import { transports } from "winston"; import type { LoggerLayers } from "../data/data"; import type { MeiLogger } from "mei-logger"; -import type { SeqLogLevel } from "seq-logging"; -const transports: Array = []; +const tports: Array = [new transports.Console({})]; -if (BotConfig.LOGGER?.SEQ_API_KEY && ProcessEnv.seqUrl) { - // Turns winston log levels into seq format. - const levelMap: Record = { - crit: "Fatal", - severe: "Error", - error: "Error", - warn: "Warning", - info: "Information", - - // Note that Seq interprets these in reverse, - // however, it's easier to read this code if I just - // use the same levels, instead of the right ones. - verbose: "Verbose", - debug: "Debug", - }; - - transports.push( - new SeqTransport({ - apiKey: BotConfig.LOGGER.SEQ_API_KEY, - serverUrl: ProcessEnv.seqUrl, - onError: (err) => { - // eslint-disable-next-line no-console - console.error(`Failed to send seq message: ${err.message}.`); - }, - levelMapper(level = "") { - return levelMap[level] ?? "Information"; - }, - }) - ); -} - -const logger = CreateLogger(`tachi-bot`, undefined, transports); +const logger = CreateLogger(`tachi-bot`, undefined, tports); export default logger; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c1d1319b..dafe1ecd2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -76,6 +76,7 @@ importers: ts-node: 10.9.1 tsconfig-paths: 3.12.0 typescript: 4.9.4 + winston: 3.5.1 dependencies: '@discordjs/builders': 0.5.0 '@discordjs/rest': 0.1.0-canary.0 @@ -101,6 +102,7 @@ importers: ts-node: 10.9.1_awa2wsr5thmg3i7jqycphctjfq tsconfig-paths: 3.12.0 typescript: 4.9.4 + winston: 3.5.1 devDependencies: '@types/express': 4.17.13 '@types/json5': 2.2.0