pinojs / pino

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

Example to redirect error logs to stdError #820

Closed robertsLando closed 4 years ago

robertsLando commented 4 years ago

By default pino uses stdOut as destination. I would like him to use stdError for all error logs levels. By digging in docs I found the only way is to use pino-tee but I cannot find any example for this

UPDATE I have been able to do this in this way:

const pino = require('pino')

const { multistream } = require('pino-multi-stream')
var streams = [
  {stream: process.stdout},
  {level: 'error', stream: process.stderr},
  {level: 'fatal', stream: process.stderr}
]

const logger = pino({
  name: 'my-app',
  level: process.env.LOG_LEVEL || 'info',
  prettyPrint: process.env.DEV ?  { levelFirst: true } : false
}, multistream(streams))

module.exports = logger
vajahath commented 3 years ago

This should be in the docs.

robertsLando commented 3 years ago

It is, at least I think I added a PR to update logs with this example

mcollina commented 3 years ago

This has been added to pino core and will be part of pino@7.

robertsLando commented 3 years ago

BTW, it's here: https://getpino.io/#/docs/help?id=log-to-different-streams

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.