refactor(logger): refactor to allow for discord to only be sent when wanted on fatals

This commit is contained in:
2025-09-01 11:27:26 -05:00
parent e73204424c
commit 84774d6b30
2 changed files with 4 additions and 4 deletions

View File

@@ -15,7 +15,6 @@ const PORT = Number(env.VITE_PORT) || 4200;
const main = async () => {
//create the logger
const log = createLogger({ module: "system", subModule: "main start" });
// base path
let basePath: string = "";
@@ -35,6 +34,7 @@ const main = async () => {
if (set.length === 0) {
return log.fatal(
{ notify: true },
"Seems like the DB is not setup yet the app will close now"
);
}

View File

@@ -14,8 +14,7 @@ const pinoLogLevels: any = {
// discord function
async function sendFatal(log: Log) {
const webhookUrl = process.env.WEBHOOK_URL!;
const payload = {
let payload = {
embeds: [
{
title: `🚨 ${env.PROD_PLANT_TOKEN}: encounter a critical error `,
@@ -73,10 +72,11 @@ export default async function (log: Log) {
message: obj.msg,
};
if (!process.env.WEBHOOK_URL) {
console.log("webhook missing?");
return;
}
if (obj.level >= 60) {
if (obj.level >= 60 && obj.notify) {
sendFatal(newlog as Log);
}
}