Uncaught exception when logging object with circular structure
See original GitHub issueIf the option “json” is set to “true” given arguments are converted to JSON. If the argument has circular structures (as it can happen easily in express environments) the formatting command fails with an exception.
This happens for the console transport beginning with line 37
if (this.json) {
this.stringify = options.stringify || function (obj) {
return JSON.stringify(obj, null, 2);
};
}
This also happens for the winston-daily-rotate-file transport
IMHO a logger should never fail while formatting the given object. Instead I would prefer if the argument in question would be omitted from logging.
What do you think?
I can provide patches if you agree.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:16
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeError: Converting circular structure to JSON - Stack ...
TypeError : Converting circular structure to JSON. It seems that I can get the object logged to the console by using just plain:...
Read more >What is TypeError: Converting circular structure to JSON?
TypeError : Converting circular structure to JSON occurs when you try to reference your variable name within the JSON object.
Read more >TypeError: cyclic object value - JavaScript - MDN Web Docs
The JavaScript exception "cyclic object value" occurs when object references ... TypeError: Converting circular structure to JSON (V8-based) ...
Read more >Logging cyclic references - JSNLog
Using the serialize option to log objects with cyclic references. ... an exception, such as: Uncaught TypeError: Converting circular structure to JSON.
Read more >Converting Circular Structure to JSON - Career Karma
JSON does not support object references, so trying to stringify a JSON object that references itself will result in a typeerror. It is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to get around this by specifying a “stringify” param in the options and using a library like circular-json:
Any update on this issue?