From b0c2f8da0446c13302b9e7274ffc789f54afd55c Mon Sep 17 00:00:00 2001 From: sarayourfriend Date: Fri, 29 Mar 2024 17:45:08 +1100 Subject: [PATCH] Always use Logger class and try to log once per event This unifies logging across the backend to always use the Logger class, always only logs to stdout (rather than an inconsistent mix of stdout and stderr, depending on whether console.error was used), and removes logging where two log events happened for the same message For example, this pattern: ```js Logger.error("Whoops, something went wrong:") console.error(err) ``` That causes two separate log events, and depending on the log transport used, could cause relevant log messages to get split across multiple events and therefore be harder (usually just more tedious) to connect and debug in production environments. --- src/backend/middlewares/RenderingMWs.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/backend/middlewares/RenderingMWs.ts b/src/backend/middlewares/RenderingMWs.ts index a0f4b397..51d7292a 100644 --- a/src/backend/middlewares/RenderingMWs.ts +++ b/src/backend/middlewares/RenderingMWs.ts @@ -134,12 +134,11 @@ export class RenderingMWs { if (err.details) { const logFn = Logger.logLevelForError(err.code) - logFn('Handled error:'); - LoggerRouter.log(logFn, req, res); // use separate rendering for detailsStr const d = err.detailsStr; delete err.detailsStr; - logFn(err); + logFn('Handled error:\n', err); + LoggerRouter.log(logFn, req, res); err.detailsStr = d; delete err.details; // do not send back error object to the client side