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 handling uncaughtException event in NodeJS application to assure that logs are flushed to ES (in my case it is AWS ES domain).
Here is the code snippet of the handler:
logger.on('finish', () => process.exit(10)).end()
where logger is created by calling winston.createLogger({...}) sometime earlier.
It appears that calling process.exit(10) on finish event emitted by the logger terminates the process of writing logs out so they are not visible on the ES side.
Having above code snippet replaced with
logger.end()
solves the problem but the application reports exit code of 0 (i.e. everything is OK) instead of desired value of 10 (i.e. something went wrong). I want to use exit code for automation.
I also tried calling end() directly at ElasticsearchTransport instead of calling it off of logger instance:
const est = logger.transports.find(e => e instanceof ElasticsearchTransport)
if (est) {
est.end()
}
The text was updated successfully, but these errors were encountered:
Ok, I understand this issue. This is probably because we emit the even logged immediately and not only when the message has been written by the bulk writer. It is however pretty hard to keep track of this if bulk writing (batching) is used. As an immediate fix, I suggest two ways:
You wait for twice the flushInterval before you process.exit(10)
You set buffering to false
I have tested none of them, they might work, please try out.
I am handling
uncaughtException
event in NodeJS application to assure that logs are flushed to ES (in my case it is AWS ES domain).Here is the code snippet of the handler:
where
logger
is created by callingwinston.createLogger({...})
sometime earlier.It appears that calling
process.exit(10)
onfinish
event emitted by the logger terminates the process of writing logs out so they are not visible on the ES side.Having above code snippet replaced with
solves the problem but the application reports exit code of
0
(i.e. everything is OK) instead of desired value of10
(i.e. something went wrong). I want to use exit code for automation.I also tried calling
end()
directly atElasticsearchTransport
instead of calling it off oflogger
instance:The text was updated successfully, but these errors were encountered: