From 6c60c3636c597c9d500108cba6d8f461430b9f96 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 26 Mar 2026 12:20:26 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20middleware=20log=20=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=A3?= =?UTF-8?q?=E0=B8=AD=E0=B8=87=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=81=E0=B8=A3?= =?UTF-8?q?=E0=B8=93=E0=B8=B5=20response=20=E0=B9=80=E0=B8=9B=E0=B9=87?= =?UTF-8?q?=E0=B8=99=20array=20#223?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ src/middlewares/logs.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e8ab805..55e347d 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,5 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +.claude \ No newline at end of file diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index e8954c7..8a0a79c 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -59,6 +59,17 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { // Get rootId from token const rootId = req.app.locals.logData?.orgRootDnaId; + let _msg = data?.message; + if (!_msg) { + if (Array.isArray(data)) { + _msg = res.statusCode >= 500 + ? "ไม่สำเร็จ" + : res.statusCode >= 400 + ? "พบข้อผิดพลาด" + : "สำเร็จ" + } + } + const obj = { logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", ip: req.ip, @@ -71,7 +82,8 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { method: req.method, endpoint: req.url, responseCode: String(res.statusCode === 304 ? 200 : res.statusCode), - responseDescription: data?.message, + // responseDescription: data?.message, + responseDescription: _msg, input: level === 4 ? JSON.stringify(req.body, null, 2) : undefined, output: level === 4 ? JSON.stringify(data, null, 2) : undefined, ...req.app.locals.logData,