From c6a821ef03be96b8f65c5d6b286eb0ad17882057 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Thu, 11 Jan 2024 14:46:50 +0200 Subject: [PATCH] chore(fe2): reducing log level for some spammy req logs (#1954) * chore(fe2): reducing log level for some spammy req logs * minor adjustment * more robust path resolution --- packages/frontend-2/server/middleware/001-logging.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/frontend-2/server/middleware/001-logging.ts b/packages/frontend-2/server/middleware/001-logging.ts index c05fca620e..f23f8a1724 100644 --- a/packages/frontend-2/server/middleware/001-logging.ts +++ b/packages/frontend-2/server/middleware/001-logging.ts @@ -42,10 +42,14 @@ export const LoggingMiddleware = pinoHttp({ // and we don't really care about 3xx stuff // all the user related 4xx responses are treated as info customLogLevel: ( - _: IncomingMessage, + req: IncomingMessage, res: ServerResponse, error: Error | undefined ) => { + // Mark some lower importance/spammy endpoints w/ 'debug' to reduce noise + const path = req.url?.split('?')[0] + const shouldBeDebug = ['/metrics', '/health'].includes(path || '') ?? false + if (res.statusCode >= 400 && res.statusCode < 500) { return 'info' } else if (res.statusCode >= 500 || error) { @@ -53,7 +57,8 @@ export const LoggingMiddleware = pinoHttp({ } else if (res.statusCode >= 300 && res.statusCode < 400) { return 'silent' } - return 'info' + + return shouldBeDebug ? 'debug' : 'info' }, customSuccessMessage(req, res) {