From b46b77d2198746d4484b45b8eff45de2865567af Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Wed, 21 Aug 2024 03:41:54 +0100 Subject: [PATCH 1/3] fix: always return a LogReturn instead of null --- src/logs.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/logs.ts b/src/logs.ts index b6c2548..667f1ec 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -6,11 +6,12 @@ export class Logs { private _maxLevel = -1; static console: PrettyLogs; - private _log({ level, consoleLog, logMessage, metadata, type }: LogParams): LogReturn | null { + private _log({ level, consoleLog, logMessage, metadata, type }: LogParams): LogReturn { // filter out more verbose logs according to maxLevel set in config - if (this._getNumericLevel(level) > this._maxLevel) return null; + if (this._getNumericLevel(level) < this._maxLevel) { + consoleLog(logMessage, metadata); + } - consoleLog(logMessage, metadata); return new LogReturn( { raw: logMessage, From 27f79808f64c26fab8a9e62d669b48878742cf31 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Wed, 21 Aug 2024 03:46:06 +0100 Subject: [PATCH 2/3] chore: remove unneeded null annotations --- src/logs.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/logs.ts b/src/logs.ts index 667f1ec..6a62c07 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -46,7 +46,7 @@ export class Logs { return metadata; } - public ok(log: string, metadata?: Metadata): LogReturn | null { + public ok(log: string, metadata?: Metadata): LogReturn { metadata = this._addDiagnosticInformation(metadata); return this._log({ level: LOG_LEVEL.INFO, @@ -57,7 +57,7 @@ export class Logs { }); } - public info(log: string, metadata?: Metadata): LogReturn | null { + public info(log: string, metadata?: Metadata): LogReturn { metadata = this._addDiagnosticInformation(metadata); return this._log({ level: LOG_LEVEL.INFO, @@ -68,7 +68,7 @@ export class Logs { }); } - public error(log: string, metadata?: Metadata): LogReturn | null { + public error(log: string, metadata?: Metadata): LogReturn { metadata = this._addDiagnosticInformation(metadata); return this._log({ level: LOG_LEVEL.ERROR, @@ -79,7 +79,7 @@ export class Logs { }); } - public debug(log: string, metadata?: Metadata): LogReturn | null { + public debug(log: string, metadata?: Metadata): LogReturn { metadata = this._addDiagnosticInformation(metadata); return this._log({ level: LOG_LEVEL.DEBUG, @@ -90,7 +90,7 @@ export class Logs { }); } - public fatal(log: string, metadata?: Metadata): LogReturn | null { + public fatal(log: string, metadata?: Metadata): LogReturn { if (!metadata) { metadata = Logs.convertErrorsIntoObjects(new Error(log)) as Metadata; const stack = metadata.stack as string[]; @@ -115,7 +115,7 @@ export class Logs { }); } - public verbose(log: string, metadata?: Metadata): LogReturn | null { + public verbose(log: string, metadata?: Metadata): LogReturn { metadata = this._addDiagnosticInformation(metadata); return this._log({ level: LOG_LEVEL.VERBOSE, From c61e2184d8d5af7bba6f2aa5362935f9ce96de34 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Wed, 21 Aug 2024 03:48:04 +0100 Subject: [PATCH 3/3] chore: use lte for maxLevel --- src/logs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logs.ts b/src/logs.ts index 6a62c07..c9d8214 100644 --- a/src/logs.ts +++ b/src/logs.ts @@ -8,7 +8,7 @@ export class Logs { private _log({ level, consoleLog, logMessage, metadata, type }: LogParams): LogReturn { // filter out more verbose logs according to maxLevel set in config - if (this._getNumericLevel(level) < this._maxLevel) { + if (this._getNumericLevel(level) <= this._maxLevel) { consoleLog(logMessage, metadata); }