gelf-stream icon indicating copy to clipboard operation
gelf-stream copied to clipboard

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

Open Gnucki opened this issue 7 years ago • 2 comments

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.

Gnucki avatar Jul 03 '17 15:07 Gnucki

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)

mhart avatar Jul 03 '17 16:07 mhart

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.

Gnucki avatar Jul 04 '17 09:07 Gnucki