You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am facing unhandledRejection exception with "winston-2.4.0". I used winston-elasticsearch with winston. But the timeout exception is not being handled by winston. Is it some bug with version 2.4.0. The error is not being returned in final callback of log. Instead it throws exception for timeout which is not being handled.
const winston = require('winston');
const ElasticSearch = require('winston-elasticsearch');
const env = process.env.ENV_MODE || 'dev';
const host = process.env.ELASTICSEARCH_HOST || '127.0.0.1';
const port = process.env.ELASTICSEARCH_PORT || 9200;
const username = process.env.ELASTICSEARCH_USERNAME || 'elastic';
const password = process.env.ELASTICSEARCH_PASSWORD || 'changeme';
const useHttps = process.env.ELASTICSEARCH_USEHTTPS || true;
const elasticOpts = [
{
protocol: useHttps === true || useHttps === 'true' ? 'https' : 'http',
host: host,
auth: `${username}:${password}`,
port: port
}
];
let indexPrefix = `${env}-${index}`;
let newInstance = new winston.Logger({
transports: [
new ElasticSearch({
handleExceptions: true,
indexPrefix,
host: host,
port: port,
clientOpts: {
host: elasticOpts
}
})]
});
newInstance.emitErrs = false;
newInstance.on('error', function (err) {
console.log('Winston Error:', err);
});
newInstance.setLevels(winston.config.npm.levels);
function log(msg, cb) {
let { level, metadata, message, index } = msg;
metadata = src_1.CommonUtils.formatMeta(metadata);
index = index || 'logs';
newInstance.log(level, message, metadata, function (err, data) {
let date = new Date();
let suffix = date.toISOString().split('T')[0].split('-').join('.');
if (cb) {
cb(err, {
message: 'Success',
messageBody: msg,
index: `${env}-${index}-${suffix}`
});
} else {
console.log('No callback provided to log function', 'error:=', err, 'message=Success', 'messageBody:=', msg);
}
});
}
The text was updated successfully, but these errors were encountered:
Idk if unhandled rejections are supported by winston 2.x. In winston 3.x there is currently a WIP PR #1462 to add support for catching unhandled rejections -- which makes me think they are not supported in 2.x either.
winston-elasticsearch does seem to have winston 3.x support so you could try using winston 3.x, but if it's truly an unhandled promise rejection rather than some other error, you might need to wait for that PR to land.
I am facing unhandledRejection exception with "winston-2.4.0". I used winston-elasticsearch with winston. But the timeout exception is not being handled by winston. Is it some bug with version 2.4.0. The error is not being returned in final callback of log. Instead it throws exception for timeout which is not being handled.
The text was updated successfully, but these errors were encountered: