From 85cd5b44e406e120145774271075960e52c5938a Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Thu, 24 Oct 2024 08:23:15 +0200 Subject: [PATCH 1/2] Fix unknown errors not appearing in log --- apps/server-asset-sg/src/app.logger.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/server-asset-sg/src/app.logger.ts b/apps/server-asset-sg/src/app.logger.ts index 29733e99..10c54fea 100644 --- a/apps/server-asset-sg/src/app.logger.ts +++ b/apps/server-asset-sg/src/app.logger.ts @@ -52,11 +52,19 @@ export class AppLogger implements LoggerService { const nameSpacer = ' '.repeat(MAX_NAME_LENGTH - level.name.length); const prefix = colors.reset(` ${now.toISOString()} `) + nameSpacer + level.bgColor(` ${level.name} `) + ' ' + source; - let output = ' ' + level.color(`${message}`); - if (params.length !== 0) { + let output = ' '; + if (!(message instanceof Error)) { + output += level.color(`${message}`); + } + if (params.length !== 0 && !(params.length === 1 && params[0] === undefined)) { + console.log({ params }); output += ' ' + stringify(params, level); } - console.log(`${prefix} ${output}`); + if (message instanceof Error) { + console.log(`${prefix} ${output}`, message); + } else { + console.log(`${prefix} ${output}`); + } } } From d588812603f7f658a144e8b9b247d2a18f4a6d0e Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Thu, 24 Oct 2024 08:25:04 +0200 Subject: [PATCH 2/2] Fix unknown errors not appearing in log --- apps/server-asset-sg/src/app.logger.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/server-asset-sg/src/app.logger.ts b/apps/server-asset-sg/src/app.logger.ts index 10c54fea..e62702dd 100644 --- a/apps/server-asset-sg/src/app.logger.ts +++ b/apps/server-asset-sg/src/app.logger.ts @@ -5,6 +5,10 @@ import colors from 'colors/safe'; export class AppLogger implements LoggerService { levels: Set | null = null; + constructor() { + colors.enable(); + } + log(message: unknown, ...optionalParams: unknown[]) { this.write(levels.log, message, optionalParams); }