feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain

This commit is contained in:
2025-09-19 22:22:05 -05:00
parent caf2315191
commit e4477402ad
847 changed files with 165801 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import {db} from "../../../database/dbclient.js";
import {logs} from "../../../database/schema/logs.js";
import build from "pino-abstract-transport";
type Log = {
username: string | null;
service: string;
level: string;
msg: string;
};
const pinoLogLevels: any = {
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) {
// Insert log entry into the PostgreSQL database using Drizzle ORM
// convert to the name to make it more easy to find later :P
const levelName = pinoLogLevels[obj.level] || "unknown";
await db.insert(logs).values({
level: levelName,
username: obj?.username.toLowerCase(),
service: obj?.service.toLowerCase(),
message: obj.msg,
});
}
});
} catch (err) {
console.error("Error inserting log into database:", err);
}
}