refactor(logger): refactor to allow for discord to only be sent when wanted on fatals
This commit is contained in:
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user