feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.03k stars 748 forks source link

Winston logger does not output Error (generate by cli) #3135

Closed psi-4ward closed 1 year ago

psi-4ward commented 1 year ago

The default index.ts create by feathers cli catches unhandled promises and logs the error using winston which does not output the error nor the stack

plain-js testcase:

const { createLogger, format, transports } = require('winston');

const logger = createLogger({
  level: 'info',
  format: format.combine(format.splat(), format.simple()),
  transports: [new transports.Console()]
})

process.on('unhandledRejection', function(reason, p) {
  console.error('[console.error] Unhandled Rejection at: Promise ', reason, p);
});

process.on(
  'unhandledRejection',
  (reason, p) =>
  logger.error('[WINSTON] Unhandled Rejection at: Promise ', p, reason)
);

(async function() {
  await new Promise((res, rej) => rej(new Error('fuubar')));
})();

output

[console.error] Unhandled Rejection at: Promise  Error: fuubar
    at ...feathers/winston-test.js:23:39
    at new Promise (<anonymous>)
    at ...feathers/winston-test.js:23:9
    at Object.<anonymous> (...feathers/winston-test.js:24:3)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 Promise {
  <rejected> Error: fuubar
      at ...feathers/winston-test.js:23:39
      at new Promise (<anonymous>)
      at ...feathers/winston-test.js:23:9
      at Object.<anonymous> (...feathers/winston-test.js:24:3)
      at Module._compile (node:internal/modules/cjs/loader:1275:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
      at Module.load (node:internal/modules/cjs/loader:1133:32)
      at Module._load (node:internal/modules/cjs/loader:972:12)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
      at node:internal/main/run_main_module:23:47
}
error: [WINSTON] Unhandled Rejection at: Promise

Notice the [WINSTON] error-log.