diff --git a/app/config/logger.js b/app/config/logger.js index 10de276..1bcdcfd 100644 --- a/app/config/logger.js +++ b/app/config/logger.js @@ -18,13 +18,26 @@ const level = process.env.LOG_LEVEL || 'info'; let transport; if (process.env.LOG_PRETTY === '1') { + // Check `pino-pretty` is actually installed BEFORE handing the + // transport config to pino. Assigning the object literal alone + // never throws — pino lazy-resolves the `target` module later + // and emits a cryptic error on startup if it's missing. The + // `require.resolve` synchronously throws MODULE_NOT_FOUND when + // the module isn't on disk, so the catch below fires cleanly + // and we fall through to default JSON output, matching the + // "pino-pretty is NOT a required dependency" header comment. try { + require.resolve('pino-pretty'); transport = { target: 'pino-pretty', options: { colorize: true, translateTime: 'SYS:standard' }, }; - } catch (_) { - // pino-pretty not installed — fall through to JSON output. + } catch (_err) { + // pino-pretty not installed — silently fall through to JSON + // output. We don't warn here because the only consumer of + // LOG_PRETTY=1 is interactive dev, and a noisy stderr line + // would clutter the very output the operator was trying to + // make readable. } }