feat: use our new logging server
Some checks failed
Code Analysis / SonarQube (push) Failing after 14s
Node.js CI / Lint and Test (push) Failing after 28s

This commit is contained in:
2025-07-07 16:30:50 -07:00
parent aaeac266f4
commit 9ea5a1f6d1
7 changed files with 21 additions and 36 deletions

View File

View File

@ -34,6 +34,7 @@
"typescript": "5.4.5"
},
"dependencies": {
"@nhcarrigan/logger": "1.0.0",
"@octokit/rest": "20.1.1",
"@prisma/client": "5.13.0",
"discord.js": "14.15.2",

8
pnpm-lock.yaml generated
View File

@ -8,6 +8,9 @@ importers:
.:
dependencies:
'@nhcarrigan/logger':
specifier: 1.0.0
version: 1.0.0
'@octokit/rest':
specifier: 20.1.1
version: 20.1.1
@ -167,6 +170,9 @@ packages:
peerDependencies:
eslint: '>=8'
'@nhcarrigan/logger@1.0.0':
resolution: {integrity: sha512-2e19Bie+ZKb6yKPKjhawqsENkhHatYkvBAmFZx9eToOXdOca+CYi51tldRMtejg6e0+4hOOf2bo5zdBQKmH0dw==}
'@nhcarrigan/prettier-config@3.2.0':
resolution: {integrity: sha512-AZOzwDTZfRiEinjUmqRj4gqZLYpLANhN1iMIsESxeuln+/BjGI06pINQsePIZ/I2HoPd+HGjNqu0S+Os9nHzuw==}
engines: {node: '20', pnpm: '8'}
@ -2398,6 +2404,8 @@ snapshots:
- supports-color
- typescript
'@nhcarrigan/logger@1.0.0': {}
'@nhcarrigan/prettier-config@3.2.0(prettier@3.2.5)':
dependencies:
prettier: 3.2.5

View File

@ -11,3 +11,4 @@ GITHUB_WEBHOOK_SECRET="op://Environment Variables - Naomi/Mod Bot/github_webhook
PATREON_WEBHOOK_SECRET="op://Environment Variables - Naomi/Mod Bot/patreon_webhook_secret"
KOFI_WEBHOOK_SECRET="op://Environment Variables - Naomi/Mod Bot/kofi_webhook_secret"
GITHUB_TOKEN="op://Environment Variables - Naomi/Mod Bot/github_pat"
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"

View File

@ -14,7 +14,7 @@ export const validateEnv = (): ExtendedClient["env"] => {
!process.env.DEBUG_HOOK ||
!process.env.MONGO_URI
) {
logHandler.log("error", "MIssing environment variables!");
logHandler.log("warn", "Missing environment variables!");
process.exit(1);
}

View File

@ -13,29 +13,15 @@ import { logHandler } from "./logHandler";
* @returns {string} A unique ID to use in logs.
*/
export const errorHandler = async (
bot: ExtendedClient,
_bot: ExtendedClient,
context: string,
err: unknown
) => {
const id = SnowflakeUtil.generate();
const error = err as Error;
logHandler.log("error", `${context}: ${error.message}`);
logHandler.log("error", JSON.stringify(error.stack, null, 2));
if (bot.env.debugHook) {
await bot.env.debugHook.send({
content: `**${id}\n${context}: ${error.message}`,
avatarURL:
bot.user?.displayAvatarURL() ??
"https://cdn.nhcarrigan.com/avatars/nhcarrigan.png",
username: bot.user?.username ?? "Mod bot"
});
await bot.env.debugHook.send({
content: "```\n" + JSON.stringify(error.stack, null, 2) + "\n```",
avatarURL:
bot.user?.displayAvatarURL() ??
"https://cdn.nhcarrigan.com/avatars/nhcarrigan.png",
username: bot.user?.username ?? "Mod bot"
});
}
void logHandler.error(
context,
error
)
return id;
};

View File

@ -1,6 +1,4 @@
import { createLogger, format, transports, config } from "winston";
const { combine, timestamp, colorize, printf } = format;
import { Logger } from "@nhcarrigan/logger";
/**
* Standard log handler, using winston to wrap and format
@ -9,16 +7,7 @@ const { combine, timestamp, colorize, printf } = format;
* @param {string} level - The log level to use.
* @param {string} message - The message to log.
*/
export const logHandler = createLogger({
levels: config.npm.levels,
level: "silly",
transports: [new transports.Console()],
format: combine(
timestamp({
format: "YYYY-MM-DD HH:mm:ss"
}),
colorize(),
printf((info) => `${info.level}: ${[info.timestamp]}: ${info.message}`)
),
exitOnError: false
});
export const logHandler = new Logger(
"Celestine",
process.env.LOG_TOKEN ?? ""
)