From 6b00ced48fb61375f2c40d22923d0230a90e8d42 Mon Sep 17 00:00:00 2001 From: Apoorv Mishra Date: Mon, 27 Feb 2023 21:36:01 +0530 Subject: [PATCH] fix: use LOG_LEVEL to set server log severity (#4937) --- .env.sample | 4 ++++ server/env.ts | 6 ++++++ server/logging/Logger.ts | 3 +-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.env.sample b/.env.sample index aa046e10c..d7480a20b 100644 --- a/.env.sample +++ b/.env.sample @@ -139,6 +139,10 @@ MAXIMUM_IMPORT_SIZE=5120000 # requests and this ends up being duplicative DEBUG=http +# Configure lowest severity level for server logs. Should be one of +# error, warn, info, http, verbose, debug and silly +LOG_LEVEL=info + # For a complete Slack integration with search and posting to channels the # following configs are also needed, some more details # => https://wiki.generaloutline.com/share/be25efd1-b3ef-4450-b8e5-c4a4fc11e02a diff --git a/server/env.ts b/server/env.ts index 6c89dcd1c..d218dbc1f 100644 --- a/server/env.ts +++ b/server/env.ts @@ -170,6 +170,12 @@ export class Environment { */ public DEBUG = process.env.DEBUG || ""; + /** + * Configure lowest severity level for server logs + */ + @IsIn(["error", "warn", "info", "http", "verbose", "debug", "silly"]) + public LOG_LEVEL = process.env.LOG_LEVEL || "info"; + /** * How many processes should be spawned. As a reasonable rule divide your * server's available memory by 512 for a rough estimate diff --git a/server/logging/Logger.ts b/server/logging/Logger.ts index 8c62c371b..da398cc0b 100644 --- a/server/logging/Logger.ts +++ b/server/logging/Logger.ts @@ -8,7 +8,6 @@ import Sentry from "@server/logging/sentry"; import * as Tracing from "./tracer"; const isProduction = env.ENVIRONMENT === "production"; -const isDev = env.ENVIRONMENT === "development"; type LogCategory = | "lifecycle" @@ -30,7 +29,7 @@ class Logger { constructor() { this.output = winston.createLogger({ - level: isDev ? "debug" : "info", + level: env.LOG_LEVEL, }); this.output.add( new winston.transports.Console({