Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exitOnError / .handleExceptions() #4

Open
mrsufgi opened this issue Jul 12, 2016 · 4 comments
Open

exitOnError / .handleExceptions() #4

mrsufgi opened this issue Jul 12, 2016 · 4 comments

Comments

@mrsufgi
Copy link

mrsufgi commented Jul 12, 2016

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 :)

@albertdb
Copy link

+1

@AlonMiz
Copy link
Contributor

AlonMiz commented Jun 3, 2018

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?

@albertdb
Copy link

albertdb commented Jun 3, 2018

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.

@AlonMiz
Copy link
Contributor

AlonMiz commented Jun 18, 2018

indeed, we would love a PR for that to be submitted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants