generated from nhcarrigan/template
feat: use our new logging server
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
+5
-16
@@ -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 ?? ""
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user