implemented new logging system in first iteration

This commit is contained in:
2025-12-31 11:26:44 -05:00
parent 46988f1921
commit d101bf9686
9 changed files with 56 additions and 49 deletions

View File

@@ -1,6 +1,6 @@
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
export type LogDepth = 'normal' | 'verbose';
export type LogType = 'http' | 'app';
export type LogType = 'http' | 'app' | 'auth';
export interface LogHeader {
timestamp: string;
@@ -27,7 +27,6 @@ function shouldLog(depth: LogDepth) {
function emitLog(header: LogHeader, payload: LogPayload = {}) {
if (!shouldLog(header.depth)) return;
console.log(header, payload);
const logLine = { ...header, ...payload };
console.log(JSON.stringify(logLine));
@@ -51,19 +50,19 @@ export const logger = {
emitLog(header, payload);
},
info(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
info(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
this.log('info', type, message, data, depth, context);
},
debug(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
debug(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
this.log('debug', type, message, data, depth, context);
},
warn(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
warn(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
this.log('warn', type, message, data, depth, context);
},
error(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
error(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
this.log('error', type, message, data, depth, context);
},
}