From 6daeea908ee3d1308bec7b3756a4bf708c18ad51 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 13 Mar 2026 14:33:41 +0100 Subject: [PATCH] Allow to set debug level in env var --- common/src/logger.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/logger.ts b/common/src/logger.ts index 900f6dae..c84c757e 100644 --- a/common/src/logger.ts +++ b/common/src/logger.ts @@ -24,7 +24,7 @@ const LOG_LEVELS: Record = { info: 1, warn: 2, error: 3, -} +} as const function shouldLog(level: LogLevel): boolean { return LOG_LEVELS[level] >= LOG_LEVELS[currentLevel()] @@ -151,6 +151,11 @@ export function logPageView(path: string): void { * @returns Current log level threshold */ const currentLevel = (): LogLevel => { + const envLogLevel = process.env.NEXT_PUBLIC_LOG_LEVEL?.toLowerCase() + if (envLogLevel) { + if (envLogLevel in LOG_LEVELS) return envLogLevel as LogLevel + console.warn(`Invalid NEXT_PUBLIC_LOG_LEVEL: ${envLogLevel}`) + } if (IS_PROD || process.env.NODE_ENV == 'production') return 'info' return 'debug' }