From 846c2c1b36ed8b8aaa73a902fa0b220ec169142d Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:23:51 +0600 Subject: [PATCH 1/8] Ensure Metadata is Properly Passed to LogReturn in Logging Class This commit addresses an issue in the logging class where the metadata parameter was not consistently passed to the LogReturn instance within the _log method. --- src/logs.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/logs.ts b/src/logs.ts index c9d8214..6e25e4a 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -12,6 +12,7 @@ export class Logs { consoleLog(logMessage, metadata); } + // Ensure metadata is set correctly in LogReturn return new LogReturn( { raw: logMessage, @@ -19,7 +20,7 @@ export class Logs { type, level, }, - metadata + metadata // Ensure metadata is passed correctly here ); } @@ -183,6 +184,7 @@ export class Logs { return -1; } } + static convertErrorsIntoObjects(obj: unknown): Metadata | unknown { // this is a utility function to render native errors in the console, the database, and on GitHub. if (obj instanceof Error) { @@ -197,6 +199,7 @@ export class Logs { obj[key] = this.convertErrorsIntoObjects(obj[key]); }); } - return obj; + + return obj; } } From 8449c259a07474a8c3cb62c2b664547267a236aa Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:44:40 +0600 Subject: [PATCH 2/8] Update constants.ts --- src/constants.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 6aaa928..efa8129 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -27,9 +27,10 @@ export const COLORS = { } as const; export const LOG_LEVEL = { - FATAL: "fatal", - ERROR: "error", - INFO: "info", - VERBOSE: "verbose", - DEBUG: "debug", + FATAL: 'fatal', + ERROR: 'error', + INFO: 'info', + VERBOSE: 'verbose', + DEBUG: 'debug', + TRACE: 'trace', // New log level } as const; From e528d9c542f04643adfc3e6b7e7ae8b2228e59d0 Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:03:52 +0600 Subject: [PATCH 3/8] Update pretty-logs.ts --- src/pretty-logs.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pretty-logs.ts b/src/pretty-logs.ts index fd89618..2037a31 100644 --- a/src/pretty-logs.ts +++ b/src/pretty-logs.ts @@ -9,6 +9,7 @@ export class PrettyLogs { this.fatal = this.fatal.bind(this); this.debug = this.debug.bind(this); this.verbose = this.verbose.bind(this); + this.trace = this.trace.bind(this); } public fatal(message: string, metadata?: Metadata | string | unknown) { this._logWithStack(LOG_LEVEL.FATAL, message, metadata); @@ -33,6 +34,10 @@ export class PrettyLogs { public verbose(message: string, metadata?: Metadata | string) { this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata); } + + public trace(message: string, metadata?: Metadata | string) { + this._logWithStack(LOG_LEVEL.TRACE, message, metadata); + } private _logWithStack(type: LogLevelWithOk, message: string, metaData?: Metadata | string | unknown) { this._log(type, message); @@ -103,6 +108,7 @@ export class PrettyLogs { info: "›", debug: "››", verbose: "💬", + trace: "🔍", }; const symbol = defaultSymbols[type]; @@ -128,6 +134,7 @@ export class PrettyLogs { info: ["info", COLORS.dim], debug: ["debug", COLORS.fgMagenta], verbose: ["debug", COLORS.dim], + trace: ["trace", COLORS.fgBlue], }; const _console = console[colorMap[type][0] as keyof typeof console] as (...args: string[]) => void; From 4d52c7c419d80025b016be76b175c31ec3e86f46 Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:05:45 +0600 Subject: [PATCH 4/8] Update logs.ts --- src/logs.ts | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/logs.ts b/src/logs.ts index 6e25e4a..83c2eee 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -12,7 +12,6 @@ export class Logs { consoleLog(logMessage, metadata); } - // Ensure metadata is set correctly in LogReturn return new LogReturn( { raw: logMessage, @@ -20,7 +19,7 @@ export class Logs { type, level, }, - metadata // Ensure metadata is passed correctly here + metadata ); } @@ -126,6 +125,17 @@ export class Logs { type: "verbose", }); } + + public trace(log: string, metadata?: Metadata): LogReturn { + metadata = this._addDiagnosticInformation(metadata); + return this._log({ + level: LOG_LEVEL.TRACE, + consoleLog: Logs.console.trace, + logMessage: log, + metadata, + type: "trace", + }); + } constructor(logLevel: LogLevel) { this._maxLevel = this._getNumericLevel(logLevel); @@ -169,22 +179,23 @@ export class Logs { } private _getNumericLevel(level: LogLevel) { - switch (level) { - case LOG_LEVEL.FATAL: - return 0; - case LOG_LEVEL.ERROR: - return 1; - case LOG_LEVEL.INFO: - return 2; - case LOG_LEVEL.VERBOSE: - return 4; - case LOG_LEVEL.DEBUG: - return 5; - default: - return -1; - } + switch (level) { + case LOG_LEVEL.FATAL: + return 0; + case LOG_LEVEL.ERROR: + return 1; + case LOG_LEVEL.INFO: + return 2; + case LOG_LEVEL.VERBOSE: + return 4; + case LOG_LEVEL.DEBUG: + return 5; + case LOG_LEVEL.TRACE: // New log level + return 6; // Assign a higher numeric value + default: + return -1; } - +} static convertErrorsIntoObjects(obj: unknown): Metadata | unknown { // this is a utility function to render native errors in the console, the database, and on GitHub. if (obj instanceof Error) { @@ -199,7 +210,6 @@ export class Logs { obj[key] = this.convertErrorsIntoObjects(obj[key]); }); } - - return obj; + return obj; } } From 8d9c19f013bc09df445716d01ed1ffeded25be3c Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:09:20 +0600 Subject: [PATCH 5/8] Update pretty-logs.ts --- src/pretty-logs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pretty-logs.ts b/src/pretty-logs.ts index 2037a31..0037787 100644 --- a/src/pretty-logs.ts +++ b/src/pretty-logs.ts @@ -133,7 +133,7 @@ export class PrettyLogs { error: ["warn", COLORS.fgYellow], info: ["info", COLORS.dim], debug: ["debug", COLORS.fgMagenta], - verbose: ["debug", COLORS.dim], + verbose: ["verbose", COLORS.dim], trace: ["trace", COLORS.fgBlue], }; From 1f814eca3c6bee60f1e3d611ef6f252d18c84c18 Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:18:16 +0600 Subject: [PATCH 6/8] Update logs.ts --- src/logs.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/logs.ts b/src/logs.ts index 83c2eee..dba2c9e 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -125,17 +125,6 @@ export class Logs { type: "verbose", }); } - - public trace(log: string, metadata?: Metadata): LogReturn { - metadata = this._addDiagnosticInformation(metadata); - return this._log({ - level: LOG_LEVEL.TRACE, - consoleLog: Logs.console.trace, - logMessage: log, - metadata, - type: "trace", - }); - } constructor(logLevel: LogLevel) { this._maxLevel = this._getNumericLevel(logLevel); From 57f89cb4300519291498504b00b22fc2a7228f7a Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:18:57 +0600 Subject: [PATCH 7/8] Update pretty-logs.ts --- src/pretty-logs.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/pretty-logs.ts b/src/pretty-logs.ts index 0037787..11b102a 100644 --- a/src/pretty-logs.ts +++ b/src/pretty-logs.ts @@ -9,7 +9,6 @@ export class PrettyLogs { this.fatal = this.fatal.bind(this); this.debug = this.debug.bind(this); this.verbose = this.verbose.bind(this); - this.trace = this.trace.bind(this); } public fatal(message: string, metadata?: Metadata | string | unknown) { this._logWithStack(LOG_LEVEL.FATAL, message, metadata); @@ -34,10 +33,6 @@ export class PrettyLogs { public verbose(message: string, metadata?: Metadata | string) { this._logWithStack(LOG_LEVEL.VERBOSE, message, metadata); } - - public trace(message: string, metadata?: Metadata | string) { - this._logWithStack(LOG_LEVEL.TRACE, message, metadata); - } private _logWithStack(type: LogLevelWithOk, message: string, metaData?: Metadata | string | unknown) { this._log(type, message); @@ -107,8 +102,7 @@ export class PrettyLogs { error: "⚠", info: "›", debug: "››", - verbose: "💬", - trace: "🔍", + verbose: "💬" }; const symbol = defaultSymbols[type]; @@ -133,8 +127,7 @@ export class PrettyLogs { error: ["warn", COLORS.fgYellow], info: ["info", COLORS.dim], debug: ["debug", COLORS.fgMagenta], - verbose: ["verbose", COLORS.dim], - trace: ["trace", COLORS.fgBlue], + verbose: ["verbose", COLORS.dim] }; const _console = console[colorMap[type][0] as keyof typeof console] as (...args: string[]) => void; From 4ba7b0361ad17379518f790a31ba32e508faacab Mon Sep 17 00:00:00 2001 From: Abu Taher Siddik <138387257+imabutahersiddik@users.noreply.github.com> Date: Tue, 29 Oct 2024 01:20:01 +0600 Subject: [PATCH 8/8] Update constants.ts --- src/constants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index efa8129..b803d0d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -32,5 +32,4 @@ export const LOG_LEVEL = { INFO: 'info', VERBOSE: 'verbose', DEBUG: 'debug', - TRACE: 'trace', // New log level } as const;