Skip to content

Commit 4f81dfe

Browse files
authored
fix: prevent missing pino logs (#729)
1 parent 3597a2d commit 4f81dfe

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/logger/pino.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { pino, Logger } from 'pino';
2-
import pretty from 'pino-pretty';
2+
import { prettyFactory } from 'pino-pretty';
3+
34
import { LogLevel } from './types';
45

5-
export const createLogger = (level: LogLevel): Logger =>
6-
pino(
6+
export const createLogger = (level: LogLevel): Logger => {
7+
const prettify = prettyFactory({ sync: true });
8+
// Configure custom stream that forwards pretty message to console
9+
// to address issues with pino pretty and Jest
10+
// Thanks to https://github.com/pinojs/pino-pretty/issues/480#issuecomment-2271709217 for the solution
11+
return pino(
712
{
813
level: level.toLowerCase(),
914
},
10-
pretty({ sync: true })
15+
{
16+
write(data: unknown) {
17+
console.log(prettify(data));
18+
},
19+
}
1120
);
21+
};

0 commit comments

Comments
 (0)