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...
This commit is contained in:
zkldi
2024-04-07 20:33:03 +01:00
parent 87e6a6fc2a
commit e66da0d3f0
4 changed files with 7 additions and 45 deletions
+2 -1
View File
@@ -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",
-8
View File
@@ -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;
}
+3 -36
View File
@@ -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<any> = [];
const tports: Array<any> = [new transports.Console({})];
if (BotConfig.LOGGER?.SEQ_API_KEY && 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",
};
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;
+2
View File
@@ -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