From 0d96a4574a016bb989434f40ce72dec2d1116397 Mon Sep 17 00:00:00 2001 From: Hampus Date: Sun, 23 Aug 2026 21:44:32 +0200 Subject: [PATCH] fix(api): read the log level and environment from the process env (#1824) --- packages/logger/src/Logger.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 2160f39a7..09c83afc4 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -20,14 +20,35 @@ interface PinoTransportOptions { }; } +const PINO_LEVELS: ReadonlyArray = ['fatal', 'error', 'warn', 'info', 'debug', 'trace']; + function isDevelopment(environment: string): boolean { return environment === 'development'; } +function isPinoLevel(value: string): value is pino.Level { + return (PINO_LEVELS as ReadonlyArray).includes(value); +} + +function resolveEnvironment(options: LoggerOptions): string { + return options.environment ?? process.env.FLUXER_ENV ?? 'production'; +} + +function resolveLevel(options: LoggerOptions, isDev: boolean): pino.Level { + if (options.level) { + return options.level; + } + const configured = process.env.LOG_LEVEL?.trim().toLowerCase(); + if (configured && isPinoLevel(configured)) { + return configured; + } + return isDev ? 'debug' : 'info'; +} + function createPinoLogger(serviceName: string, options: LoggerOptions = {}): PinoLogger { - const environment = options.environment ?? 'production'; + const environment = resolveEnvironment(options); const isDev = isDevelopment(environment); - const level = options.level ?? (isDev ? 'debug' : 'info'); + const level = resolveLevel(options, isDev); const streams: Array = []; if (isDev) { try {