From af3fb23488b5b484c5dca15e0830e13f32f11f2b Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 16 Dec 2024 13:13:19 -0500 Subject: [PATCH 1/5] put response data in correct format for logging --- web-api/src/logger.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web-api/src/logger.ts b/web-api/src/logger.ts index 2bc1e530acd..7843e1a4ab3 100644 --- a/web-api/src/logger.ts +++ b/web-api/src/logger.ts @@ -43,13 +43,15 @@ export const expressLogger = (req, res, next) => { end.apply(this, arguments); const responseTimeMs = new Date() - req.locals.startTime; - logger.info(`Request ended: ${req.method} ${req.url}`, { + logger.addContext({ response: { responseSize: parseInt(res.get('content-length') ?? '0'), responseTimeMs, statusCode: res.statusCode, }, }); + + logger.info(`Request ended: ${req.method} ${req.url}`); logger.clearContext(); }; From 7c3ca4783bd43fe5167f1a5e14f01229604bb553 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 16 Dec 2024 13:42:07 -0500 Subject: [PATCH 2/5] fix failing test --- web-api/src/logger.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web-api/src/logger.test.ts b/web-api/src/logger.test.ts index ac23105cdbd..e0b12b0c5e8 100644 --- a/web-api/src/logger.test.ts +++ b/web-api/src/logger.test.ts @@ -61,11 +61,12 @@ describe('logger', () => { const instance = req.locals.logger; instance.info = jest.fn(); + instance.addContext = jest.fn(); res.end(); - expect(instance.info).toHaveBeenCalledWith( - expect.any(String), + expect(instance.info).toHaveBeenCalledWith(expect.any(String)); + expect(instance.addContext).toHaveBeenCalledWith( expect.objectContaining({ response: expect.objectContaining({ statusCode: 200, From ecab81085b921392f0d7a350a5965725132b77c1 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 16 Dec 2024 13:58:02 -0500 Subject: [PATCH 3/5] fix other failing tests --- web-api/src/logger.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-api/src/logger.test.ts b/web-api/src/logger.test.ts index e0b12b0c5e8..9df943eb3e6 100644 --- a/web-api/src/logger.test.ts +++ b/web-api/src/logger.test.ts @@ -61,7 +61,7 @@ describe('logger', () => { const instance = req.locals.logger; instance.info = jest.fn(); - instance.addContext = jest.fn(); + jest.spyOn(instance, 'addContext'); res.end(); From 097a5cee7231d4903f879a7e8e9df115360f4a2f Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 17 Dec 2024 15:18:36 -0500 Subject: [PATCH 4/5] trigger build to fix failing test From f4d5498b6f028bc85c39badc5dd8a1e1d062ea36 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 17 Dec 2024 15:55:21 -0500 Subject: [PATCH 5/5] trigger build to fix failing test again