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

Node: %O (big O) pretty-prints the object #322

Merged
merged 4 commits into from
Dec 12, 2016

Conversation

TooTallNate
Copy link
Contributor

For example:

var o = {
 foo: 'bar',
 b: new Buffer(10),
 c: Math.PI
}

debug('%O', o)

Previously:

 foo { foo: 'bar', b: <Buffer 01 00 00 00 01 00 00 00 c0 82>, c:
3.141592653589793 } +0ms

Now:

 foo { foo: 'bar',
 foo   b: <Buffer 01 00 00 00 01 00 00 00 c0 82>,
 foo   c: 3.141592653589793 } +0ms

This is a breaking change for anybody relying on the old %O behavior.
Though I don't think %O was working previously because the formatters
regexp wasn't checking for uppercase formatters (now fixed in this patch).

@z-vr
Copy link

z-vr commented Nov 7, 2016

How can I print objects with many layers on one line?

@TooTallNate
Copy link
Contributor Author

How can I print objects with many layers on one line?

Using lower-case %o formatter.

@z-vr
Copy link

z-vr commented Nov 8, 2016

@TooTallNate it doesn't do the job though, it prints { func: { result: [ [Object], [Object] ] } } for debug('%o', { func: { result } });

@TooTallNate
Copy link
Contributor Author

Yes I see. We need a way to configure the depth on a debug instance, and default to something a bit higher than util.inspect()'s default depth value.

@TooTallNate
Copy link
Contributor Author

^ That should probably be a separate PR though.

@thebigredgeek
Copy link
Contributor

@TooTallNate thinking minor semver for this?

@TooTallNate
Copy link
Contributor Author

Well considering %O was completely broken before, than ya minor is probably fine. The default behavior of debug(obj) is changing here though so anybody relying on that (for tests, for example) would be failing after an upgrade. So maybe major would be safer in that case.

@thebigredgeek
Copy link
Contributor

@TooTallNate kinda thinking we should expand the API for depth with this release. Set a default value and make the api option for changing depth non-breaking. Thoughts?

@TooTallNate TooTallNate changed the title %O (big O) pretty-prints the object Node: %O (big O) pretty-prints the object Nov 10, 2016
@thebigredgeek
Copy link
Contributor

@TooTallNate can you update the docs

@thebigredgeek thebigredgeek added change-minor This proposes or provides a change that requires a minor release needs-documentation This issue or change requires additional documentation feature This proposes or provides a feature or enhancement labels Nov 14, 2016
@thebigredgeek
Copy link
Contributor

Also @TooTallNate can you add docs for this in the PR as well?

@thebigredgeek thebigredgeek added this to the 2.4.0 milestone Nov 14, 2016
@thebigredgeek
Copy link
Contributor

@TooTallNate any update on docs man? Also, we need to resolve conflicts on this. I'd like to release 2.4 this week

For example:

```js
var debug = require('./')('foo')

var o = {
  foo: 'bar',
  b: new Buffer(10),
  c: Math.PI
}

debug('%O', o)
```

Previously:

```
  foo { foo: 'bar', b: <Buffer 01 00 00 00 01 00 00 00 c0 82>, c: 3.141592653589793 } +0ms
```

Now:

```
  foo { foo: 'bar',
  foo   b: <Buffer 01 00 00 00 01 00 00 00 c0 82>,
  foo   c: 3.141592653589793 } +0ms
```

This is a breaking change for anybody relying on the old `%O` behavior.
Though I don't think `%O` was working previously because the formatters
regexp wasn't checking for uppercase formatters (now fixed in this patch).
@thebigredgeek thebigredgeek merged commit 00f3046 into master Dec 12, 2016
@thebigredgeek thebigredgeek deleted the feature/pretty-print-big-o branch December 12, 2016 19:13
@jfoclpf
Copy link

jfoclpf commented Apr 14, 2018

@z-vr you may try this, it fully prints the object, but you lose colours

const util  = require('util');
debug(util.inspect(yourObj, {showHidden: false, depth: null}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change-minor This proposes or provides a change that requires a minor release feature This proposes or provides a feature or enhancement needs-documentation This issue or change requires additional documentation
Development

Successfully merging this pull request may close these issues.

4 participants