mhart / gelf-stream

A node.js stream to send JS objects to a Graylog2 server (in GELF format)
Other
29 stars 13 forks source link

'flatten' function leads to a stack overflow on circular reference #16

Open Gnucki opened 7 years ago

Gnucki commented 7 years ago

Hi!

When the 'flatten' function try to flatten a circular reference, it try to flatten until a stack overflow occurs. I see 3 solutions to solve that problem:

  1. Limit flattening to a defined level (pretty easy)
  2. Look for circular references (a bit harder)
  3. Ask people to not log circular references

Tell me if you prefer a solution. I can make a PR if you want.

mhart commented 7 years ago

Is this using the provided Bunyan mapper with forBunyan? If so, you can provide your own mapping function:

var GelfStream = require('gelf-stream').GelfStream
var stream = new GelfStream(host, port, {map: myMappingFunction})

See how this is done in the source: https://github.com/mhart/gelf-stream/blob/master/gelf-stream.js#L117-L119

(or you could just get rid of any circular references before logging)

Gnucki commented 7 years ago

Yes, I use forBunyan. Of course, it is a solution if you do not want an evolution.

I do not see a way to get rid of that circular reference occuring in the response object of restify which is logged at trace level.

Thanks for your quick advice.