winston-elasticsearch: Logger transports for elastic gets deleted when there is an error writing the logs to Elasticsearch
When there is an error writing logs to the elasticsearch (for example writing different types for a field), the error subscription is invoked the first time successfully. However on subsequent errors, the logger fails with the error “[winston ]Attempt to write logs with no transports” The reason is because the elastic transport in the logger gets deleted after the exception.
var logger = winston.createLogger({
transports: [
new Elasticsearch(esTransportOpts)
],
exitOnError: false
});
logger .on('error', (err) => {
// elastic transport is deleted in logger object
console.log('error writing to elasticsearch');
});
Expected Results: The transport should not be deleted after the exception.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 16 (8 by maintainers)
@vanthome this issue appeared after these changes: https://github.com/vanthome/winston-elasticsearch/commit/819de70f4f62d4f23c86438b0de5bf3a889786a8#diff-3805ebf53854d461672e5b174ef6a719
when you emit an error it just unpipes the stream and the transport closes immediately. https://github.com/nodejs/readable-stream/blob/master/lib/_stream_readable.js#L702 if you comment this line, transport won’t be closed. from the other side, we want to be notified about elasticsearch errors, so probably you can just replace
errorevent withwarnor something. the issue seems really critical, please take a look at it.no, the stream can handle that internally. I hope I can deliver this in the coming days.
In our project this issue lead to “Unhandled Rejection at Promise” errors which is critical for us. @vanthome Can you already estimate when you will have time to look at this?