diff --git a/web-api/src/logger.test.ts b/web-api/src/logger.test.ts index ac23105cdbd..9df943eb3e6 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(); + jest.spyOn(instance, 'addContext'); 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, 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(); };