winston-logzio
winston-logzio copied to clipboard
exitOnError / .handleExceptions()
Hey,
I've tried adding the exitOnError and handleExceptions to my logger but they don't work.
I'm using different containers and I want one container to exitOnError and handleExcepetions because critical errors are not being sent (because the app shutdown too early..)
thanks :)
+1
Hi, using: "winston": "^2.4.1", "winston-logzio": "^1.0.8"
i have tried this code:
const winston = require('winston');
const winstonLogzIO = require('winston-logzio');
const loggerOptions = {
token: 'ekByhvPZHSsGvYOGfAkrEpHIiFvybwzH',
type: 'bla', // OPTIONAL (If none is set, it will be 'nodejs')
debug: true,
};
const logzIOTransport = new (winstonLogzIO)(loggerOptions);
const logger = new (winston.Logger)({
transports: [
logzIOTransport
],
exceptionHandlers: [
logzIOTransport
],
exitOnError: true // set this to true
});
process.on('uncaughtException', function (err) {
console.error("UncaughtException processing: %s", err);
logger.error("UncaughtException processing: %s", err);
logzIOTransport.flush(function (callback) {
process.exit(1);
});
});
winston.log('info', { 'wwp': 'asd' });
setTimeout(() => procces.exit(), 3000);
throw new Error('test error');
and logs were sent successfuly
info: wwp=asd
UncaughtException processing: Error: test error
logzio-nodejs: Sending last messages and closing...
logzio-nodejs: Sending bulk #1
UncaughtException processing: ReferenceError: procces is not defined
logzio-nodejs: Sending last messages and closing...
logzio-nodejs: Sending bulk #2
can you elaborate, or share a code snippet with the issue?
Process.on statement wouldn't be necessary if handleExceptions worked properly. In other words, that is the "patchy" way of handling exceptions, specially when having to flush the transport.
indeed, we would love a PR for that to be submitted 👍