From 831318d94137331b382d3dd9710dee62c9ae67e3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 22 Jun 2023 09:17:25 -0400 Subject: [PATCH] fix: Invalid LOG_LEVEL in environment results in server crash with no displayed error message Related: https://github.com/outline/outline/discussions/5466 --- server/logging/Logger.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server/logging/Logger.ts b/server/logging/Logger.ts index 116029d10..0e3a93647 100644 --- a/server/logging/Logger.ts +++ b/server/logging/Logger.ts @@ -30,7 +30,20 @@ class Logger { public constructor() { this.output = winston.createLogger({ - level: env.LOG_LEVEL, + // The check for log level validity is here in addition to the ENV validation + // as entering an incorrect LOG_LEVEL in env could otherwise prevent the + // related error message from being displayed. + level: [ + "error", + "warn", + "info", + "http", + "verbose", + "debug", + "silly", + ].includes(env.LOG_LEVEL) + ? env.LOG_LEVEL + : "info", }); this.output.add( new winston.transports.Console({