From 6c95e9d5e09f689ad91c8adc69335e1daa05aaa9 Mon Sep 17 00:00:00 2001 From: Boris D Date: Mon, 6 Oct 2025 16:41:56 +0300 Subject: [PATCH] feat: add logging entity and types for structured log records --- .gitignore | 3 +++ src/query/logs/entities/log.entity.ts | 20 ++++++++++++++++++++ src/query/logs/logs.type.ts | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/query/logs/entities/log.entity.ts create mode 100644 src/query/logs/logs.type.ts diff --git a/.gitignore b/.gitignore index c1193d9..088b3cf 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +!src/query/logs +!src/query/logs/* + # Runtime data pids *.pid diff --git a/src/query/logs/entities/log.entity.ts b/src/query/logs/entities/log.entity.ts new file mode 100644 index 0000000..5b2d167 --- /dev/null +++ b/src/query/logs/entities/log.entity.ts @@ -0,0 +1,20 @@ +import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; +import { LogRecord } from "../logs.type"; + +@Entity("logs") +export class LogEntity { + @PrimaryGeneratedColumn("uuid") + id: string; + + @Column({ + type: "longtext", + nullable: false, + transformer: { + to: (value: any) => JSON.stringify(value), + from: (value: any) => JSON.parse(value), + }, + }) + record: LogRecord; + + // TODO: projectId +} diff --git a/src/query/logs/logs.type.ts b/src/query/logs/logs.type.ts new file mode 100644 index 0000000..e3195ae --- /dev/null +++ b/src/query/logs/logs.type.ts @@ -0,0 +1,12 @@ +export type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL"; + +export type LogLine = { + timestamp: string; + message: string; + level: LogLevel; +}; + +export type LogRecord = { + id: string; + lines: LogLine[]; +};