pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

Pino errors do not raise 'error' event #565

Closed spazmodius closed 5 years ago

spazmodius commented 5 years ago

It seems that Pino does not raise it's 'error' event.

const logger = pino(dest).on('error', (err) => {
  console.log('Never gets here', err)
})

How should one handle, say, a transport that goes away? Is it expected that calls to Pino will be try/catch'd? Even that would not catch errors that happen during an async write operation.

mcollina commented 5 years ago

Logging should be errorless. console.log does not error, and you should not expect that any logging call could error.

That being said, have you got a specific case to reproduce this? There is no error in pino: only the transport destination thaf you pass in could emit error, so you should listen to its error there.

spazmodius commented 5 years ago

Ah, of course. Yes, I can hook the 'error' event on the destination, assuming I opened it myself. I suppose there's no way to hook it if I pass a path or fd directly to pino()?

davidmarkclements commented 5 years ago

@spazmodius - you can't pass an fd, and we recommend using pino.destination:

const pino = require('pino')
const dest = pino.destination('/some/path')
dest.on('error', () => { ... })
const logger = pino(dest)
davidmarkclements commented 5 years ago

closing as there is a way to handle destination errors

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.