pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

[BUG] Piping non-ASCII output breaks console.log #324

Open matheusb-comp opened 2 years ago

matheusb-comp commented 2 years ago

Detected this situation while running a code that prints a QR code to the terminal using qrcode-terminal. It was using the small option, and checking the code, the lib seems to just print some unicode characters.

Example script:

const num = 15;
const char = '🐞';
[...Array(num)].forEach(() => console.log(char));
setInterval(() => console.log('A'), 1000);

When running this script piping the output (node index.js | pino-pretty), the higher num is, the longer it takes for the A logs to appear in the terminal, and when it happens, many of them are shown at once, instead of every second.

Running the code without piping to pino-pretty, or changing char to ASCII, like a dot (.), makes everything run normal again.

Environment

SO: Ubuntu 21.10 impish Node: v17.2.0 pino-pretty: 7.6.0

mcollina commented 2 years ago

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

matheusb-comp commented 2 years ago

Sorry, but I don't believe I have enough knowledge about stream transformation to send a PR to fix this. I tried looking at the code and got confused about how it actually works.

As a workaround, I'm now using pino-pretty via programmatic integration, but using an environment variable to add the transport.target only in development.

jsumners commented 2 years ago

This looks like a stream is buffering, but the defaults I see for the pino-pretty cli do not create a buffered stream?

AntennaeVY commented 1 year ago

This is still not fixed as of July 2023. Still waiting, can't use pino pretty along with qrcode-terminal