refactor(biome): formats from biome
This commit is contained in:
@@ -1,42 +1,42 @@
|
||||
import build from "pino-abstract-transport";
|
||||
import { db } from "../db/db.js";
|
||||
import { logs, type Log } from "../db/schema/logs.js";
|
||||
import { type Log, logs } from "../db/schema/logs.js";
|
||||
import { tryCatch } from "../utils/tryCatch.js";
|
||||
|
||||
const pinoLogLevels: any = {
|
||||
10: "trace",
|
||||
20: "debug",
|
||||
30: "info",
|
||||
40: "warn",
|
||||
50: "error",
|
||||
60: "fatal",
|
||||
10: "trace",
|
||||
20: "debug",
|
||||
30: "info",
|
||||
40: "warn",
|
||||
50: "error",
|
||||
60: "fatal",
|
||||
};
|
||||
// Create a custom transport function
|
||||
export default async function (log: Log) {
|
||||
//const {username, service, level, msg, ...extra} = log;
|
||||
try {
|
||||
return build(async function (source) {
|
||||
for await (let obj of source) {
|
||||
// convert to the name to make it more easy to find later :P
|
||||
const levelName = pinoLogLevels[obj.level] || "unknown";
|
||||
//const {username, service, level, msg, ...extra} = log;
|
||||
try {
|
||||
return build(async (source) => {
|
||||
for await (const obj of source) {
|
||||
// convert to the name to make it more easy to find later :P
|
||||
const levelName = pinoLogLevels[obj.level] || "unknown";
|
||||
|
||||
const res = await tryCatch(
|
||||
db.insert(logs).values({
|
||||
level: levelName,
|
||||
module: obj?.module?.toLowerCase(),
|
||||
subModule: obj?.subModule?.toLowerCase(),
|
||||
hostname: obj?.hostname?.toLowerCase(),
|
||||
message: obj.msg,
|
||||
stack: obj?.stack,
|
||||
})
|
||||
);
|
||||
const res = await tryCatch(
|
||||
db.insert(logs).values({
|
||||
level: levelName,
|
||||
module: obj?.module?.toLowerCase(),
|
||||
subModule: obj?.subModule?.toLowerCase(),
|
||||
hostname: obj?.hostname?.toLowerCase(),
|
||||
message: obj.msg,
|
||||
stack: obj?.stack,
|
||||
}),
|
||||
);
|
||||
|
||||
if (res.error) {
|
||||
console.log(res.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error inserting log into database:", err);
|
||||
}
|
||||
if (res.error) {
|
||||
console.log(res.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error inserting log into database:", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
import pino, { type Logger } from "pino";
|
||||
|
||||
export let logLevel = process.env.LOG_LEVEL || "info";
|
||||
export const logLevel = process.env.LOG_LEVEL || "info";
|
||||
|
||||
const transport = pino.transport({
|
||||
targets: [
|
||||
{
|
||||
target: "pino-pretty",
|
||||
options: {
|
||||
colorize: true,
|
||||
singleLine: true,
|
||||
// customPrettifiers: {
|
||||
// time: (time) => `🕰 ${time}`,
|
||||
// },
|
||||
destination: process.stdout.fd,
|
||||
},
|
||||
},
|
||||
{
|
||||
target: "./dbTransport.js",
|
||||
},
|
||||
{
|
||||
target: "./notification.js",
|
||||
},
|
||||
// Only log to Go if LST_USE_GO=true
|
||||
...(process.env.LST_USE_GO === "true"
|
||||
? [
|
||||
{
|
||||
target: "./goTransport.js", // New transport for Go
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
targets: [
|
||||
{
|
||||
target: "pino-pretty",
|
||||
options: {
|
||||
colorize: true,
|
||||
singleLine: true,
|
||||
// customPrettifiers: {
|
||||
// time: (time) => `🕰 ${time}`,
|
||||
// },
|
||||
destination: process.stdout.fd,
|
||||
},
|
||||
},
|
||||
{
|
||||
target: "./dbTransport.js",
|
||||
},
|
||||
{
|
||||
target: "./notification.js",
|
||||
},
|
||||
// Only log to Go if LST_USE_GO=true
|
||||
...(process.env.LST_USE_GO === "true"
|
||||
? [
|
||||
{
|
||||
target: "./goTransport.js", // New transport for Go
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
|
||||
export const rootLogger: Logger = pino(
|
||||
{
|
||||
level: logLevel,
|
||||
redact: { paths: ["email", "password"], remove: true },
|
||||
},
|
||||
transport
|
||||
{
|
||||
level: logLevel,
|
||||
redact: { paths: ["email", "password"], remove: true },
|
||||
},
|
||||
transport,
|
||||
);
|
||||
|
||||
/**
|
||||
* factory to create child to log things for us
|
||||
*/
|
||||
export function createLogger(bindings: Record<string, unknown>): Logger {
|
||||
return rootLogger.child(bindings);
|
||||
return rootLogger.child(bindings);
|
||||
}
|
||||
|
||||
@@ -1,52 +1,51 @@
|
||||
import build from "pino-abstract-transport";
|
||||
import { type Log } from "../db/schema/logs.js";
|
||||
import type { Log } from "../db/schema/logs.js";
|
||||
import { validateEnv } from "../utils/envValidator.js";
|
||||
import { sendNotify } from "../utils/notify.js";
|
||||
|
||||
const env = validateEnv(process.env);
|
||||
|
||||
const pinoLogLevels: any = {
|
||||
10: "trace",
|
||||
20: "debug",
|
||||
30: "info",
|
||||
40: "warn",
|
||||
50: "error",
|
||||
60: "fatal",
|
||||
10: "trace",
|
||||
20: "debug",
|
||||
30: "info",
|
||||
40: "warn",
|
||||
50: "error",
|
||||
60: "fatal",
|
||||
};
|
||||
// discord function
|
||||
|
||||
export default async function (log: Log) {
|
||||
//const {username, service, level, msg, ...extra} = log;
|
||||
try {
|
||||
return build(async function (source) {
|
||||
for await (let obj of source) {
|
||||
// convert to the name to make it more easy to find later :P
|
||||
const levelName = pinoLogLevels[obj.level] || "unknown";
|
||||
//const {username, service, level, msg, ...extra} = log;
|
||||
try {
|
||||
return build(async (source) => {
|
||||
for await (const obj of source) {
|
||||
// convert to the name to make it more easy to find later :P
|
||||
const levelName = pinoLogLevels[obj.level] || "unknown";
|
||||
|
||||
const newlog = {
|
||||
level: levelName,
|
||||
module: obj.module
|
||||
? String(obj.module).toLowerCase()
|
||||
: undefined,
|
||||
subModule: obj.subModule
|
||||
? String(obj.subModule).toLowerCase()
|
||||
: undefined,
|
||||
hostname: obj.hostname
|
||||
? String(obj.hostname).toLowerCase()
|
||||
: undefined,
|
||||
message: obj.msg,
|
||||
stack: obj.stack ? obj.stack : undefined,
|
||||
};
|
||||
if (!process.env.WEBHOOK_URL) {
|
||||
console.log("WebHook is missing we wont move foward.");
|
||||
return;
|
||||
}
|
||||
const newlog = {
|
||||
level: levelName,
|
||||
module: obj.module ? String(obj.module).toLowerCase() : undefined,
|
||||
subModule: obj.subModule
|
||||
? String(obj.subModule).toLowerCase()
|
||||
: undefined,
|
||||
hostname: obj.hostname
|
||||
? String(obj.hostname).toLowerCase()
|
||||
: undefined,
|
||||
message: obj.msg,
|
||||
stack: obj.stack ? obj.stack : undefined,
|
||||
};
|
||||
if (!process.env.WEBHOOK_URL) {
|
||||
console.log("WebHook is missing we wont move foward.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.level >= 60 && obj.notify) {
|
||||
sendNotify(newlog as Log);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error inserting log into database:", err);
|
||||
}
|
||||
if (obj.level >= 60 && obj.notify) {
|
||||
sendNotify(newlog as Log);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error inserting log into database:", err);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user