Skip to content

Commit

Permalink
Merge pull request #1252 from FoalTS/fix-log-dev2
Browse files Browse the repository at this point in the history
Improve safety logging
  • Loading branch information
LoicPoullain authored Apr 16, 2024
2 parents a4a4508 + 3ee7cbb commit a78ced2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/core/src/common/logging/logger.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 -"', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/logging/logger.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a78ced2

Please sign in to comment.