Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/config/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}

Expand Down