kenperkins / winston-papertrail

Papertrail transport for Winston
MIT License
203 stars 94 forks source link

Winston crashes process (solved) & does NOT reconnect to Papertrail after LOST connection (open) #90

Open thebarty opened 5 years ago

thebarty commented 5 years ago

Hi guys,

woohhhaaa! my winston setup crashes the process when the connection to papertrail is lost:

    "winston": "^3.2.1",
    "winston-papertrail": "^1.0.5"
        const papertrailLogger = new winston.transports.Papertrail({
            // for options see https://github.com/kenperkins/winston-papertrail
            host,
            port,
            level: 'info',
            logFormat(level, message) {
                return `[${level}] ${message}`
            },
            inlineMeta: true,  // attach meta data inline (TODO switch it off completely see https://github.com/kenperkins/winston-papertrail/issues/85)
        })
        papertrailLogger.on('error', (err) => {
            // Handle, report, or silently ignore connection errors and failures
            console.error('[Log] papertrailLogger.error', err)
        })
        transports.push(papertrailLogger)
ERROR:
{ Error: write EADDRNOTAVAIL
W20191014-09:57:04.888(2)? (STDERR)     at _errnoException (util.js:992:11)
W20191014-09:57:04.888(2)? (STDERR)     at WriteWrap.afterWrite (net.js:864:14)
W20191014-09:57:04.888(2)? (STDERR)   code: 'EADDRNOTAVAIL',
W20191014-09:57:04.888(2)? (STDERR)   errno: 'EADDRNOTAVAIL',
W20191014-09:57:04.889(2)? (STDERR)   syscall: 'write' }
W20191014-09:57:04.889(2)? (STDERR) events.js:183
W20191014-09:57:04.889(2)? (STDERR)       throw er; // Unhandled 'error' event
W20191014-09:57:04.889(2)? (STDERR)       ^
W20191014-09:57:04.890(2)? (STDERR) 

and

W20191014-09:57:10.430(2)? (STDERR) [Log] papertrailLogger.error { Error: getaddrinfo ENOTFOUND logsXXXX.papertrailapp.com logsXXXX.papertrailapp.com:123124
W20191014-09:57:10.430(2)? (STDERR)     at errnoException (dns.js:50:10)
W20191014-09:57:10.430(2)? (STDERR)     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
W20191014-09:57:10.431(2)? (STDERR)   code: 'ENOTFOUND',
W20191014-09:57:10.431(2)? (STDERR)   errno: 'ENOTFOUND',
W20191014-09:57:10.431(2)? (STDERR)   syscall: 'getaddrinfo',
W20191014-09:57:10.431(2)? (STDERR)   hostname: 'logsXXXX.papertrailapp.com',
W20191014-09:57:10.431(2)? (STDERR)   host: 'logsXXXX.papertrailapp.com',
W20191014-09:57:10.431(2)? (STDERR)   port: 123124 }
W20191014-09:57:10.431(2)? (STDERR) events.js:183
W20191014-09:57:10.432(2)? (STDERR)       throw er; // Unhandled 'error' event
W20191014-09:57:10.432(2)? (STDERR)       ^
W20191014-09:57:10.432(2)? (STDERR) 
W20191014-09:57:10.432(2)? (STDERR) Error: getaddrinfo ENOTFOUND logsXXXX.papertrailapp.com logsXXXX.papertrailapp.com:123124
W20191014-09:57:10.432(2)? (STDERR)     at errnoException (dns.js:50:10)
W20191014-09:57:10.432(2)? (STDERR)     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)

I wouldn't expect a pro-logger library to need a try-catch.

Is this package still maintained?

thebarty commented 5 years ago

Ok I have found a solution to prevent crashes:

add this line to your config

            handleExceptions: true,  // see https://github.com/winstonjs/winston#exceptions

like

        const papertrailLogger = new winston.transports.Papertrail({
            // for options see https://github.com/kenperkins/winston-papertrail
            host,
            port,
            level: 'info',
            logFormat(level, message) {
                return `[${level}] ${message}`
            },
            inlineMeta: true,  // attach meta data inline (TODO switch it off completely see https://github.com/kenperkins/winston-papertrail/issues/85)
            handleExceptions: true,  // see https://github.com/winstonjs/winston#exceptions
        })
thebarty commented 5 years ago

I can provoke this locally by switching off WLAN.

The remaining problem is that AFTER LOOSING the connection once, it does NOT reconnect to papertrail.

Any idea how to have winston RECONNECT to papertrail?

kdolan commented 5 years ago

I have same issue with no ability to reconnect. I have had that issue for a while now, it's rather annoying. If anybody has a fix for this it would be much appreciated.

paulhklam1122 commented 3 years ago

Yes, having trouble with this issue too. We're trying to use this in an electron app context.

kylebuildsstuff commented 3 years ago

Been having the same issue for a while too, and switching to the syslog transport, or adding handleExceptions to the transport and logger doesn't prevent the crash for my apps. I've been thinking of switching to http logs but I don't know if it's going to have the same problem too or if it's just going to be much slower.