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

Limit depth of output in console.log for nested objects, and add console.dir #826

Merged
merged 6 commits into from
Sep 30, 2018

Conversation

maxwyb
Copy link
Contributor

@maxwyb maxwyb commented Sep 25, 2018

Some improvements on Console to mimic the behavior of Node.js (if this's what we want to do):

  1. console.log only shows up to 3 levels for nested objects. Deeper structures are shown as [object].
  2. Add console.dir function which supports depth parameter, to customize output nested levels.

This's my first PR to the deno repo and please let me know for any suggestions. Thanks guys!

@CLAassistant
Copy link

CLAassistant commented Sep 25, 2018

CLA assistant check
All committers have signed the CLA.

@maxwyb maxwyb changed the title Add default console.log depth and console.dir with depth parameter. Limit depth of output in console.log for nested objects, and add console.dir Sep 25, 2018
js/console.ts Outdated
const out: string[] = [];
for (const a of args) {
if (typeof a === "string") {
out.push(a);
} else {
// tslint:disable-next-line:no-any
out.push(stringify(new Set<any>(), a));
out.push(stringify(new Set<any>(), a, 0, options.depth || DEFAULT_MAX_DEPTH));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes we just want no depth at all. Perhaps you should add a check where if options.depth is 0, take it instead of defaulting to 2. In case of null, we could either default it to 0 (implying no depth), 2 (default depth), or Infinity (implying lack of depth).

Same for line 136.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, now null and undefined (if user does not provide this option) defaults to 2 (default depth). Other values including 0 are treated as valid values.

Copy link

@t829702 t829702 Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this null treated as default to 2 is different with node:

in Node this null is treated as unlimited depth

> var o = { a: { b: { c: { d: new Date } } } };
undefined
> console.log(o)
{ a: { b: { c: [Object] } } }
> console.dir(o, { depth: null });
{
  a: { b: { c: { d: 2020-08-19T23:55:58.009Z } } }
}

@kevinkassimo
Copy link
Contributor

kevinkassimo commented Sep 25, 2018

@maxwyb Travis tests are failing. I think you might want to run ./tools/format.py and ./tools/lint.py and push again

@maxwyb
Copy link
Contributor Author

maxwyb commented Sep 25, 2018

Thanks for letting me know. Will work on it after a few hours when I get back home.

@ry
Copy link
Member

ry commented Sep 30, 2018

@maxwyb - Could you please rebase / resolve conflicts - change looks reasonable - but I can't land it as is currently.

@maxwyb
Copy link
Contributor Author

maxwyb commented Sep 30, 2018

Thanks for taking a look! Seems like there's a small linting error left, I will resolve it after lunch and push.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@ry ry merged commit bcdbfc0 into denoland:master Sep 30, 2018
ry added a commit to ry/deno that referenced this pull request Oct 4, 2018
- Improve fetch headers (denoland#853)
- Add deno.truncate (denoland#805)
- Add copyFile/copyFileSync (denoland#863)
- Limit depth of output in console.log for nested objects, and add
  console.dir (denoland#826)
- Guess extensions on extension not provided (denoland#859)
- Renames:
  deno.platform -> deno.platform.os
  deno.arch -> deno.platform.arch
- Upgrade TS to 3.0.3
- Add readDirSync(), readDir()
- Add support for TCP servers and clients. (denoland#884)
  Adds deno.listen(), deno.dial(), deno.Listener and deno.Conn.
@ry ry mentioned this pull request Oct 4, 2018
ry added a commit that referenced this pull request Oct 4, 2018
- Improve fetch headers (#853)
- Add deno.truncate (#805)
- Add copyFile/copyFileSync (#863)
- Limit depth of output in console.log for nested objects, and add
  console.dir (#826)
- Guess extensions on extension not provided (#859)
- Renames:
  deno.platform -> deno.platform.os
  deno.arch -> deno.platform.arch
- Upgrade TS to 3.0.3
- Add readDirSync(), readDir()
- Add support for TCP servers and clients. (#884)
  Adds deno.listen(), deno.dial(), deno.Listener and deno.Conn.
hardfist pushed a commit to hardfist/deno that referenced this pull request Aug 7, 2024
Bumped versions for 0.295.0

Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants