Skip to content
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

Expose inspect to allow custom object formatting #266

Closed
wants to merge 1 commit into from
Closed

Expose inspect to allow custom object formatting #266

wants to merge 1 commit into from

Conversation

kevinoid
Copy link

This PR 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.

Note: This PR currently exposes the .inspect property both on debug itself and on the instances. It can be useful for overriding, but if you wanted to minimize the API expansion, it could be exposed as _inspect on debug or otherwise hidden.

Thanks for considering,
Kevin

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 <[email protected]>
@thebigredgeek
Copy link
Contributor

Closing in lieu of #327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants