From 2c66c66a39d7494d6a999ac5fda0a5ed29b44f48 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 21 Jan 2021 15:44:58 +0100 Subject: [PATCH] logging: add status code description for redirections --- src/components/LogRequestsComponent.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/LogRequestsComponent.ts b/src/components/LogRequestsComponent.ts index 3476d6d..78d0e0b 100644 --- a/src/components/LogRequestsComponent.ts +++ b/src/components/LogRequestsComponent.ts @@ -46,7 +46,14 @@ export default class LogRequestsComponent extends ApplicationComponent { req.log.info(requestObj); } } else { - let logStr = `${req.ip} < ${req.method} ${req.originalUrl} - ${res.statusCode}`; + let codeDescription = ''; + if (res.statusCode === 301) { + codeDescription = 'Permanent redirect to ' + res.getHeader('location'); + } else if (res.statusCode === 302) { + codeDescription = 'Temporary redirect to ' + res.getHeader('location'); + } + + let logStr = `${req.ip} < ${req.method} ${req.originalUrl} - ${res.statusCode} ${codeDescription}`; if (err) { if (err instanceof Error) { if (silent) {