feat: bring back seq for the bot

This commit is contained in:
zkldi
2024-04-16 17:42:40 +01:00
parent 4f0b0f081a
commit e0d5f8df18
2 changed files with 39 additions and 0 deletions
+5
View File
@@ -106,6 +106,8 @@ export interface ProcessEnvironment {
nodeEnv: "dev" | "production" | "staging" | "test";
mongoUrl: string;
port: integer;
seqUrl?: string;
seqApiKey?: string;
}
function ParseEnvVars() {
@@ -123,6 +125,7 @@ function ParseEnvVars() {
p.isPositiveInteger(Number(self)) === true ||
"Should be a string representing a whole integer port.",
SEQ_URL: "*string",
SEQ_API_KEY: "*string",
},
{},
{ allowExcessKeys: true }
@@ -138,6 +141,8 @@ function ParseEnvVars() {
nodeEnv: process.env.NODE_ENV,
mongoUrl: process.env.MONGO_URL,
port: Number(process.env.PORT),
seqUrl: process.env.SEQ_URL,
seqApiKey: process.env.SEQ_API_KEY,
} as ProcessEnvironment;
}
+34
View File
@@ -1,10 +1,44 @@
import { Transport as SeqTransport } from "@valuabletouch/winston-seq";
import { 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 tports: Array<any> = [new transports.Console({})];
if (ProcessEnv.seqUrl) {
// Turns winston log levels into seq format.
const levelMap: Record<string, SeqLogLevel> = {
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",
};
tports.push(
new SeqTransport({
apiKey: ProcessEnv.seqApiKey,
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, tports);
export default logger;