docs(logs): changes how logs are put into the db they will be there name vs key
This commit is contained in:
@@ -8,6 +8,15 @@ type Log = {
|
|||||||
level: string;
|
level: string;
|
||||||
msg: string;
|
msg: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pinoLogLevels: any = {
|
||||||
|
10: "trace",
|
||||||
|
20: "debug",
|
||||||
|
30: "info",
|
||||||
|
40: "warn",
|
||||||
|
50: "error",
|
||||||
|
60: "fatal",
|
||||||
|
};
|
||||||
// Create a custom transport function
|
// Create a custom transport function
|
||||||
export default async function (log: Log) {
|
export default async function (log: Log) {
|
||||||
//const {username, service, level, msg, ...extra} = log;
|
//const {username, service, level, msg, ...extra} = log;
|
||||||
@@ -15,8 +24,11 @@ export default async function (log: Log) {
|
|||||||
return build(async function (source) {
|
return build(async function (source) {
|
||||||
for await (let obj of source) {
|
for await (let obj of source) {
|
||||||
// Insert log entry into the PostgreSQL database using Drizzle ORM
|
// 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({
|
await db.insert(logs).values({
|
||||||
level: obj.level,
|
level: levelName,
|
||||||
username: obj?.username.toLowerCase(),
|
username: obj?.username.toLowerCase(),
|
||||||
service: obj?.service.toLowerCase(),
|
service: obj?.service.toLowerCase(),
|
||||||
message: obj.msg,
|
message: obj.msg,
|
||||||
|
|||||||
Reference in New Issue
Block a user