winston version?_winston@2winston@3 node -v outputs:_ v10.16.0In both below cases nodejs will print default unhandled rejection error
1) setting handleRejections flag to true during transport creation is not working
2) calling logger.rejections.handle(transport) is not working
Winston should intercept unhandled rejection and log it
1st problem is due to not released change in winston-transport package: https://github.com/winstonjs/winston-transport/issues/47
2nd problem is due to typo in _addHandler method of lib/winston/rejection-handler.js: https://github.com/winstonjs/winston/blob/15c9653e4eeae1c76875603a722e11db9a6556bd/lib/winston/rejection-handler.js#L153
This line should be ADDED handler.handleRejections = true
There is one important thing: without handleExceptions, handleRejections won't log anything, due to below check: https://github.com/winstonjs/winston-transport/blob/46db8f3c8cd8b106ade8d7e04a191ee388683d60/index.js#L70
Fails
const { createLogger, transports } = require('winston');
const logger = createLogger({
transports: new transports.Console({
level: 'info',
handleRejections: true,
}),
});
logger.info('Start');
new Promise((resolve, reject) => {
process.nextTick(() => {
reject(new Error('Rejected'));
});
}).then(() => {});
Succeeds (Trick is in using Object.assign on transport instance)
const { createLogger, transports } = require('winston');
const logger = createLogger({
transports: Object.assign(
new transports.Console({
handleExceptions: true,
}),
{
handleRejections: true,
},
),
});
logger.info('Start');
new Promise((resolve, reject) => {
process.nextTick(() => {
reject(new Error('Rejected'));
});
}).then(() => {});
Any progress on this?
Any update on this? The documentation of winston@3 on github shows the rejections section but it is not available on the npm package page.
I think this is fixed with #1779 and can be closed?
Probably, and winston-transport was released 2 months ago with required change too. I will re-test with latest version
Looks like issue is fixed, but only if handleExceptions is also set to true
Still not working
Most helpful comment
Any update on this? The documentation of
winston@3on github shows the rejections section but it is not available on the npm package page.