node-bunyan
node-bunyan copied to clipboard
Deeply nested [Objects] and how to stringify them.
Related to #189 and especially #439 whose solution did not work for me under bunyan 1.8.5.
I have the requirement to log a full object, but deep objects are truncated to [Object].
See zipkin-js 's span object which has a .toJSON() that returns another simpler object as well. This object is input as logger.info(span.toJSON()) and output as such:
{"name":"calltracing","hostname":"SFO1M-C02ND01R","pid":71394,"level":30,
"msg":"{ traceId: '3be6e54d7c7dfbfc211500a4e4392e42',\n name: 'POST',\n id: '211500a4e4392e42',\n annotations: \n [ { value: 'sr', timestamp: 1492039789064437, endpoint: [Object] },\n { value: 'ss', timestamp: 1492039789787671, endpoint: [Object] } ],\n binaryAnnotations: \n [ { key: 'http.url', value: '/phx/localEcho', endpoint: [Object] },\n { key: 'http.status_code', value: '401', endpoint: [Object] } ] }",
"time":"2017-04-12T23:29:49.791Z","v":0}
And despite it being an object, it doesn't turn out as strictly legal JSON but the loose style of JSON with linebreaks?
What I end up having to do is JSON.stringify(span.toJSON()) and send that string to bunyan, which results in an extra ugly string encoding.
Is there any other way to get the full object's contents passed through bunyan and into the log, which avoids the string encoding? I can't set the depth for the entire process, as I'm just a library.
FYI, the end log looks like:
{"name":"calltracing","hostname":"SFO1M-C02ND01R","pid":72315,"level":30,
"msg":"{\"traceId\":\"8a404b3419bf2c06675523fa33b5ebeb\",\"name\":\"POST\",\"id\":\"675523fa33b5ebeb\",\"annotations\":[{\"value\":\"sr\",\"timestamp\":1492040364351497,\"endpoint\":{\"serviceName\":\"phoenix\",\"ipv4\":\"10.21.86.218\",\"port\":0}},{\"value\":\"ss\",\"timestamp\":1492040365035091,\"endpoint\":{\"serviceName\":\"phoenix\",\"ipv4\":\"10.21.86.218\",\"port\":0}}],\"binaryAnnotations\":[{\"key\":\"http.url\",\"value\":\"/phx/localEcho\",\"endpoint\":{\"serviceName\":\"phoenix\",\"ipv4\":\"10.21.86.218\",\"port\":0}},{\"key\":\"http.status_code\",\"value\":\"401\",\"endpoint\":{\"serviceName\":\"phoenix\",\"ipv4\":\"10.21.86.218\",\"port\":0}}]}",
"time":"2017-04-12T23:39:25.038Z","v":0}
And what I'd like it to look like is:
{"name":"calltracing","hostname":"SFO1M-C02ND01R","pid":73692,"level":30,
"msg":{"traceId":"f40e5526967d1733622a0a84e795dc4e","name":"POST","id":"622a0a84e795dc4e","annotations":[{"value":"sr","timestamp":1492041234694821,"endpoint":{"serviceName":"phoenix","ipv4":"10.21.86.218","port":0}},{"value":"ss","timestamp":1492041235377582,"endpoint":{"serviceName":"phoenix","ipv4":"10.21.86.218","port":0}}],"binaryAnnotations":[{"key":"http.url","value":"/phx/localEcho","endpoint":{"serviceName":"phoenix","ipv4":"10.21.86.218","port":0}},{"key":"http.status_code","value":"401","endpoint":{"serviceName":"phoenix","ipv4":"10.21.86.218","port":0}}]},
"time":"2017-04-12T23:53:55.381Z","v":0}
Came here to ask the same question, been playing with this for way too long trying to get something sane and it appears impossible to have an object output in actual JSON, surprisingly.
Yeah I'd like to bump my own thread, as I am now facing feedback from the users of my library that they don't like to stringify their objects either.
I am not sure I understand the question
I also have the same question