breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
3.06k stars 79 forks source link

error when use with pino log #37

Closed meotimdihia closed 4 years ago

meotimdihia commented 4 years ago

in jobs/test.js:

export {}
require('dotenv').config()
const pino = require('pino')
let logger = pino({
  customLevels: {
    critical: 70
  }
})
process.on('uncaughtException', pino.final(logger, (err, finalLogger) => {
  finalLogger.error(err, 'uncaughtException')
  process.exit(1)
}))

err: Error: final requires a stream that has a flushSync method, such as pino.destination and pino.extreme

I think the issue was related to this: https://github.com/pinojs/pino/issues/761

meotimdihia commented 4 years ago

Another bug is Bree not work good with Pino:

const bree = new Bree({
  logger: pino
....

example:

{"level":30,"time":1600514925288,"pid":11138,"hostname":"ip-10-0-0-21","msg":"Worker for job \"test\" online"} {"level":50,"time":1600514925658,"pid":11138,"hostname":"ip-10-0-0-21","msg":"Worker for job \"test\" had an error"} {"level":50,"time":1600514925673,"pid":11138,"hostname":"ip-10-0-0-21","msg":"Worker for job \"test\" exited with code 1"} Stacktrace is completely missing from logs. Full logs:

Worker for job "test" had an error {
  err: Error: final requires a stream that has a flushSync method, such as pino.destination and pino.extreme
      at Function.final...
       ......
niftylettuce commented 4 years ago

You should use it like this:

const pino = require('pino')({
  customLevels: {
    log: 30
  },
  hooks: {
    // <https://github.com/pinojs/pino/blob/master/docs/api.md#logmethod>
    logMethod(inputArgs, method) {
      return method.call(this, {
        // <https://github.com/pinojs/pino/issues/854>
        // message: inputArgs[0],
        msg: inputArgs[0],
        meta: inputArgs[1]
      });
    }
  }
});

See https://cabinjs.com for further reference.