winstonjs / winston-syslog

A syslog transport for winston
http://github.com/winstonjs/winston-syslog
MIT License
137 stars 119 forks source link

Causes thrown error when log is written before TCP connects #103

Open knightcode opened 6 years ago

knightcode commented 6 years ago

If the logger is written to before a TCP connection is established, the following code executes to properly queue the log message, but then it passes err to the log's callback, which produces the error below for me.

Someone would know better than, but it seems like if you're queuing the message, it's mildly acceptable to pass a success condition to callback.

winston-syslog.js, line 129

    this.connect((err) => {
      if (err) {
        //
        // If there was an error enqueue the message
        //
        this.queue.push(syslogMsg);

        return callback(err);  <------- 'err' bubbles up to logger
      }
Error: Unhandled "error" event. (true)
    at DerivedLogger.emit (events.js:186:19)
    at DerivedLogger.transportError (/docs/savory/savorycatering/node_modules/winston/lib/winston/logger.js:504:12)
    at emitOne (events.js:121:20)
    at Syslog.emit (events.js:211:7)
    at onwriteError (_stream_writable.js:412:12)
    at onwrite (_stream_writable.js:440:5)
    at connect (/docs/savory/savorycatering/node_modules/winston-syslog/lib/winston-syslog.js:138:16)
    at Syslog.connect (/docs/savory/savorycatering/node_modules/winston-syslog/lib/winston-syslog.js:272:5)
    at Syslog.log (/docs/savory/savorycatering/node_modules/winston-syslog/lib/winston-syslog.js:130:10)
    at Syslog.TransportStream._write (/docs/savory/savorycatering/node_modules/winston-transport/index.js:88:17)
    at doWrite (_stream_writable.js:397:12)
    at writeOrBuffer (_stream_writable.js:383:5)
    at Syslog.Writable.write (_stream_writable.js:290:11)
    at DerivedLogger.ondata (/docs/savory/savorycatering/node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:619:20)
    at emitOne (events.js:116:13)
    at DerivedLogger.emit (events.js:211:7)
    at addChunk (/docs/savory/savorycatering/node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:291:12)
    at readableAddChunk (/docs/savory/savorycatering/node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:278:11)
    at DerivedLogger.Readable.push (/docs/savory/savorycatering/node_modules/winston/node_modules/readable-stream/lib/_stream_readable.js:245:10)
    at DerivedLogger.Transform.push (/docs/savory/savorycatering/node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:148:32)
    at DerivedLogger._transform (/docs/savory/savorycatering/node_modules/winston/lib/winston/logger.js:210:12)
    at DerivedLogger.Transform._read (/docs/savory/savorycatering/node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:184:10)
Esya commented 6 years ago

Same for us, does anyone have a solution for this? This causes an unhandled exception and crashes our app

knightcode commented 6 years ago

I forked the repo and made changes to fix this and the other issue I posted here: https://github.com/Savorylabs/winston-syslog

The simple fix is only for those who can tolerate lack of feedback.

While this repo is dormant, you can add this to your package.json to get fetch it:

    "winston-syslog": "https://github.com/Savorylabs/winston-syslog/archive/2.0.1.tar.gz",
massimopibiri commented 5 years ago

I forked the repo and made changes to fix this and the other issue I posted here: https://github.com/Savorylabs/winston-syslog

The simple fix is only for those who can tolerate lack of feedback.

While this repo is dormant, you can add this to your package.json to get fetch it:

    "winston-syslog": "https://github.com/Savorylabs/winston-syslog/archive/2.0.1.tar.gz",

Thank you. That's cool!