-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the output from console.log of objects and collections on Node.js #2758
Comments
I am not aware of any way to do this without overriding the global |
We need to define a function and store it on the Realm.Object prototype as the [util.inspect.custom] symbol: See https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_custom_inspection_functions_on_objects
I disagree: I see no reason we would ask that of our users and I would not expect an average user to think of that when being frustrated while debugging their app. I believe we can (and should) do better. Also - this wouldn't work for a large collection or objects with cyclic relationships. I don't think we need to strive for a cross platform solution here, to my knowledge the console API is not standardized - and if other platforms have similar issues, we should of course capture issues and try to fix that too. |
Let me paraphrase my comment. There is no way i can see we can support console.log the way you have described without overriding the global.console.log function. The util.inspect.custom is a nodejs way to provide support for custom output for util.inspect only. Which is a step away from the usability you want to achieve using console.log. since its behind a 'require' and then the code doing it is not crossplatform |
"react-native": "0.61.5", |
I'm mentioning this because
I don't think I understand that comment. We can easily attempt a require in a way that wouldn't interfere with other platforms? |
I am not against the initial intent of this issue. Anything that can ease the developer is a must have. But I think we need to find a good cross platform way of doing object inspection which provides the same behavior on all platforms, whenever possible.
Unfortunately this does work under the VS Code debugger. Which goes to show even on nodejs environment this seems not reliable/ideal way of doing it. Having this working, depending if a debugger is attached or not will be even more confusing. A better option would be providing this ourselves in the form of |
For what it's worth, this used to work. I'm upgrading from realm 2.17.0 to 10.3.0, and I have a bunch of failing Jest snapshots that look like this: (Jest uses pretty-format for serializing objects into string). EDIT: Looks like in case of Jest, this issue specifically affects Realm object types that are defined using JavaScript classes ( |
Curious if any updates here? Is there an alternative option to console.log() that can show more about the Realm objects? Thanks! |
Goals
Using console.log during debugging is a fairly common practice and the output of calling this on an object or collection from a Realm should be informative.
Expected Results
I would expect that logging a
Collection
of objects (such asResults
) would give information on the type of items in the collection, the size of the collection and perhaps a preview of the first couple of elements in the collection. As a reference, callingconsole.log
on an array and objects yields respectively:Actual Results, Steps to Reproduce & Code Sample
In addition to this, in the Node.js REPL, when executing an expression the REPL prints its value, for a collection, this prints:
All of the output above have very limited value to a user while debugging their code.
NOTE: https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_custom_inspection_functions_on_objects might come in handy when solving this.
Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: