Expose inspect to allow custom object formatting#266
Closed
kevinoid wants to merge 1 commit into
Closed
Conversation
This commit exposes the inspect method, which is used to format objects for the `%o` formatting directive, so that it can be called or replaced to suit the needs of users. Some use cases for this are #185 (inspect with same coloring as debug) and #263 ("better" object formatting). My primary use case is to log objects with a smaller depth to avoid spamming the logs from large/deep objects. Other use cases include using the showHidden and customInspect options of util.inspect. Why not just use `util.inspect` or another custom formatting function directly? My major reasons are: * It takes more code since every debugged object must be formatted. * It's not available on browsers, complicating Universal/Isomorphic JavaScript (or interfering with the inspector if polyfilled). * It adds unnecessary formatting overhead when debugging is disabled. * It doesn't match debug output colorization without using the undocumented .useColors property. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Contributor
|
Closing in lieu of #327 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR exposes the
inspectmethod, which is used to format objects for the%oformatting directive, so that it can be called or replaced to suit the needs of users.Some use cases for this are #185 (inspect with same coloring as debug) and #263 ("better" object formatting). My primary use case is to log objects with a smaller depth to avoid spamming the logs from large/deep objects. Other use cases include using the
showHiddenandcustomInspectoptions of
util.inspect.Why not just use
util.inspector another custom formatting function directly? My major reasons are:.useColorsproperty.Note: This PR currently exposes the
.inspectproperty both ondebugitself and on the instances. It can be useful for overriding, but if you wanted to minimize the API expansion, it could be exposed as_inspectondebugor otherwise hidden.Thanks for considering,
Kevin