From 5c8e01c03414539f79c2f5db52847813bd4589a9 Mon Sep 17 00:00:00 2001 From: sarayourfriend Date: Fri, 29 Mar 2024 17:40:49 +1100 Subject: [PATCH] Configure log levels for specific error types --- src/backend/Logger.ts | 22 ++++++++++++++++++++++ src/backend/middlewares/RenderingMWs.ts | 3 +-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/backend/Logger.ts b/src/backend/Logger.ts index 19a72cc5..ddea11f3 100644 --- a/src/backend/Logger.ts +++ b/src/backend/Logger.ts @@ -1,5 +1,6 @@ import {Config} from '../common/config/private/Config'; import {LogLevel} from '../common/config/private/PrivateConfig'; +import {ErrorCodes} from '../common/entities/Error'; const forcedDebug = process.env['NODE_ENV'] === 'debug'; @@ -103,4 +104,25 @@ export class Logger { }); console.log(date + tag + LOG_TAG, ...args); } + + public static logLevelForError(e: ErrorCodes): LoggerFunction { + switch (e) { + case ErrorCodes.INPUT_ERROR: + case ErrorCodes.NOT_AUTHENTICATED: + case ErrorCodes.ALREADY_AUTHENTICATED: + case ErrorCodes.NOT_AUTHORISED: + case ErrorCodes.PERMISSION_DENIED: + case ErrorCodes.CREDENTIAL_NOT_FOUND: + return Logger.debug + case ErrorCodes.SETTINGS_ERROR: + case ErrorCodes.TASK_ERROR: + case ErrorCodes.JOB_ERROR: + case ErrorCodes.THUMBNAIL_GENERATION_ERROR: + case ErrorCodes.PHOTO_GENERATION_ERROR: + case ErrorCodes.SERVER_ERROR: + return Logger.error + default: + return Logger.warn + } + } } diff --git a/src/backend/middlewares/RenderingMWs.ts b/src/backend/middlewares/RenderingMWs.ts index 5af9c8ba..bb4ca0c1 100644 --- a/src/backend/middlewares/RenderingMWs.ts +++ b/src/backend/middlewares/RenderingMWs.ts @@ -132,8 +132,7 @@ export class RenderingMWs { ): void { if (err instanceof ErrorDTO) { if (err.details) { - Logger.warn('Handled error:'); - LoggerRouter.log(Logger.warn, req, res); + LoggerRouter.log(logFn, req, res); // use separate rendering for detailsStr const d = err.detailsStr; delete err.detailsStr;