ref(utils): Improve logging of objects in logger
methods
#4663
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a variable is used in a template string, its
.toString()
method is called, and most non-native objects, when stringified with.toString()
, come out as"[object Object]"
. In ourlogger
, we use a template string to concatenate all of the arguments we're given. As a result, users can get error messages like:in cases where the error is not an actual
Error
, which is obviously not very helpful.The underlying
console
methods upon which ourlogger
methods rely can generally do better, though, and will attempt to print the actual contents of any object they're given. You can see the difference here:This PR changes the
logger
methods so that they pass their arguments on to theconsole
methods intact, rather than as a pre-concatenated string, in order to be able to take advantage of the improved logging of objects. It also changes all instances of "error while" logs like the one above to pass their error objects separately rather than as part of a template string, in order to take advantage of this change.Note: There are almost certainly other places in the repo where we log objects which could benefit from this change. In the interests of time, however, this PR is restricted to the ones which brought this issue to light, and others can be solved in future PRs as necessary.