From 8a6fcd70dbaafc89916020bf0f2d96369fdfb108 Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Wed, 7 May 2025 15:30:32 +0530 Subject: [PATCH] fix(api): update logging (#60210) --- api/src/routes/public/user.ts | 4 +++- api/src/utils/logger.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/api/src/routes/public/user.ts b/api/src/routes/public/user.ts index 7fe5b8d38bd..97cd4f6b7c0 100644 --- a/api/src/routes/public/user.ts +++ b/api/src/routes/public/user.ts @@ -222,8 +222,10 @@ export const userPublicGetRoutes: FastifyPluginCallbackTypebox = ( const logger = fastify.log.child({ req, res: reply }); if (req.validationError) { - logger.warn('Validation error: No username provided'); void reply.code(400); + logger + .child({ res: reply }) + .warn('Validation error: No username provided'); return await reply.send({ type: 'danger', message: 'username parameter is required' diff --git a/api/src/utils/logger.ts b/api/src/utils/logger.ts index 9ece05dd97f..4f7e741719f 100644 --- a/api/src/utils/logger.ts +++ b/api/src/utils/logger.ts @@ -19,6 +19,12 @@ const serializersPretty = { REQ_METHOD: req.method, REQ_URL: req.url }; + }, + res: (res: FastifyReply) => { + return { + RES_STATUS_CODE: res.statusCode, + RES_ELAPSED_TIME: res.elapsedTime + }; } }; @@ -50,10 +56,10 @@ const serializersDefault = { REQ_ID: id }; }, - res: (reply: FastifyReply) => { + res: (res: FastifyReply) => { return { - RES_STATUS_CODE: reply.statusCode, - RES_RESPONSE_TIME: reply.elapsedTime + RES_STATUS_CODE: res.statusCode, + RES_ELAPSED_TIME: res.elapsedTime }; } };