pinojs/pino

Logs buffering/batching output to stdout despite sync: true

Open

#1,497 创建于 2022年7月19日

在 GitHub 查看
 (26 评论) (1 反应) (0 负责人)JavaScript (13,157 star) (839 fork)batch import
help wanted

描述

I'm seeing logs batch-written into the syslog and trying to figure out what's going on.

Runtime is a fairly stock Ubuntu image on EC2, nothing fancy.

The app is very low-log volume, producing only about 6-10 log messages per minute. It's running as a standard service in systemctl, and logs to stdout and therefore to syslog.

The behavior I'm seeing is that log messages seem to buffer for some number of minutes, (sometimes as many as 3 or more minutes) and then a batch of logs will arrive to /var/log/syslog all at once. The syslog timestamps of these will all match the time of the batch arrival, but the pino timestamps show the messages were originally logged fairly evenly throughout the buffering period.

Screen Shot 2022-07-18 at 9 38 16 PM

Here is my pino config, where I've tried explicitly setting synchronous mode:

const pino = require('pino') // v 8.1.0

const logger = pino({
  timestamp: pino.stdTimeFunctions.isoTime,
}, pino.destination({ sync: true }))

I've also tried this, with no difference in behavior.

const logger = pino({
  timestamp: pino.stdTimeFunctions.isoTime,
})

The problem seems to get worse the longer the app runs, as at first startup there is no buffering at all.

I do not see the buffering behavior when using console.log on the same machine.

Any help appreciated!

UPDATE As noted in https://github.com/pinojs/pino/issues/1497#issuecomment-1195037176, this was due to use of an emoji in the log statement, which resulted in the byte length written being incorrectly calculated, a known issue in sonic-boom and referenced below.

贡献者指南

Logs buffering/batching output to stdout despite sync: true · pinojs/pino#1497 | Good First Issue