mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-13 01:38:29 +03:00
feat: bring back seq for the bot
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user