mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 19:38:13 +03:00
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:
+2
-1
@@ -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",
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
|
||||
Generated
+2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user