diff --git a/packages/core/src/common/logging/logger.utils.spec.ts b/packages/core/src/common/logging/logger.utils.spec.ts index 96c56f5912..1a353468d8 100644 --- a/packages/core/src/common/logging/logger.utils.spec.ts +++ b/packages/core/src/common/logging/logger.utils.spec.ts @@ -206,6 +206,19 @@ describe('formatMessage', () => { strictEqual(actual, expected); }); + + it('should return a text with a well-formatted message (unexpected undefined status code).', () => { + const message = 'HTTP request - GET /foo/bar'; + const params = { + statusCode: undefined, + responseTime: null, + }; + + const actual = formatMessage('info', message, params, 'dev', now); + const expected = `\u001b[90m[${localeTimeNow}]\u001b[39m \u001b[36mINFO\u001b[39m GET /foo/bar undefined - null ms` + + strictEqual(actual, expected); + }); }); context('given the message is a socket.io log and is prefixed by "Socket.io message received -"', () => { diff --git a/packages/core/src/common/logging/logger.utils.ts b/packages/core/src/common/logging/logger.utils.ts index 0f4dfed136..cb8c9a6055 100644 --- a/packages/core/src/common/logging/logger.utils.ts +++ b/packages/core/src/common/logging/logger.utils.ts @@ -63,7 +63,7 @@ function getColoredStatusCode(statusCode: number | null): string { if (statusCode >= 200) { return `\u001b[32m${statusCode}\u001b[39m`; } - return statusCode.toString(); + return `${statusCode}`; } function getColoredStatus(status: 'ok'|'error'): string {