implemented new logging system in first iteration
This commit is contained in:
@@ -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);
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user