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

Implement console.group #1716

Closed
Rich-Harris opened this issue May 16, 2015 · 32 comments
Closed

Implement console.group #1716

Rich-Harris opened this issue May 16, 2015 · 32 comments
Labels
console Issues and PRs related to the console subsystem. feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol

Comments

@Rich-Harris
Copy link

It might be totally impractical to do this properly, so I'll understand if it's immediately closed as wontfix, but a) it'd be really useful, and b) @domenic sent me here!

Basically, it'd be really great if there was something vaguely equivalent to console.group, as it's incredibly useful for debugging in the browser. I whipped up node-console-group which is a very naive implementation (can't handle wrapped lines, etc) but good enough for my current needs - does this seem like something that would be worth fleshing out and adding to io.js?

@brendanashworth brendanashworth added the feature request Issues that request new features to be added to Node.js. label May 16, 2015
@silverwind
Copy link
Contributor

This looks to be implemented in all major browsers, so +1 for parity. I think your example is a bit too fancy on whitespace, and we should probably only handle the indentation (2 chars?) and maybe add a character on the first char, like |.

@rlidwka
Copy link
Contributor

rlidwka commented May 17, 2015

What are use-cases for it?

I see this method for the first time honestly.

@Fishrock123
Copy link
Contributor

This looks like it can be done in userland just fine? Is there any thing we need to better support it? Otherwise I'm -1.

@silverwind
Copy link
Contributor

It can be done in userland, but what about compatibilty with scripts using these console methods? They'd unnecessarily error out.

@mscdex
Copy link
Contributor

mscdex commented May 17, 2015

I think I'm +1 on the general idea, since we already have most other console.* functions that browsers provide.

However, I'm not sure about the proposed formatting. Perhaps there is some other layout that might scale better with nesting? Maybe we could (additionally) support some sort of level parameter like util.inspect() has?

@yosuke-furukawa
Copy link
Member

I am +1, because we are better to implement same api on browser as possible.
BUT, console is a PANDORA box .....

DeveloperToolsWG members are trying to standardize console API.
According to the doc

node/io.js unimplemented:

  • console.clear
  • console.count
  • console.debug
  • console.dirxml
  • console.table
  • console.group / groupCollapsed / groupEnd
  • console.isIndependentlyComposed
  • console.profile/profileEnd
  • console.timeline/timelineEnd
  • console.timeStamp

node/io.js implemented but different behavior from browsers

  • format specifier
Specifier Description node/io.js implement status
%s Formats the value as a string (cooercing via toString() if necessary) same
%d, %i Formats the value as an integer Formats the value as a number (not integer and %i is not implemented)
%f Formats the value as a floating point value not implemented but %d is implemented
%o Formats the value as an expandable DOM Element (or JavaScript Object if it is not) not implemented
%O Formats the value as an expandable JavaScript Object not implemented but %j is implemented
%c Formats the output string according to CSS styles you provide not implemented

We need to define what API should be implemented / should not be implemented.
And if we implement the API, we should follow the standardize API specification.

@Rich-Harris
Copy link
Author

What are use-cases for it?

It makes logging output much more legible, especially when you have a lot of it. It's particularly useful when you have a function that gets called frequently, and you want to understand how (or if) it's being called from a particular point in your code. It's also very useful for understanding anything that happens recursively, because there's visual structure involved.

My words aren't really doing it justice, but it's a bit like going from alert() to console.log() - you can just debug a lot more efficiently.

I'm not sure about the proposed formatting

That's fair - in fact I'm not really proposing it, as such, it's just what I cobbled together this afternoon. I'm certain it can be improved.

Thanks for considering this. I totally understand the preference for userland solutions, though as @Fishrock123 notes it does necessitate monkey-patching.

@imyller
Copy link
Member

imyller commented May 17, 2015

👍 just for the parity with browsers. As stated, there does not seem to be official standard for console API, but these nearly match:

I think Node should implement something code-compatible with these and then later move to standardized console API if there ever is going to be one.

@imyller
Copy link
Member

imyller commented May 17, 2015

Even Microsoft IE/Chakra JS has now console.group, console.groupCollapsed, console.groupEnd:

@silverwind
Copy link
Contributor

This should be quite easy to implement. The general consensus seems to be in favor.

  • console.group should add one level of indentation
  • console.groupEnd should remove one level of indentation
  • console.groupCollapsed should be a noop in our case aliased to console.group

As for styling, I'd suggest just two spaces as a start.

@silverwind silverwind added good first issue Issues that are suitable for first-time contributors. console Issues and PRs related to the console subsystem. and removed feature request Issues that request new features to be added to Node.js. labels May 18, 2015
@imyller
Copy link
Member

imyller commented May 18, 2015

@silverwind Actually console.groupCollapsed should be same as console.group(). It is expected to be followed by console.groupEnd() too.

console.groupCollapsed()
Creates a new logging group that is initially collapsed instead of open, as with console.group().

@silverwind
Copy link
Contributor

Right, misinterpreted that. Should be aliased to console.group.

@3y3
Copy link

3y3 commented May 18, 2015

This should be quite easy to implement. The general consensus seems to be in favor.

  • console.group should add one level of indentation
  • console.groupEnd should remove one level of indentation
  • console.groupCollapsed should be a noop in our case aliased to console.group

console.groupCollapsed should be implemented as real function. In this case external gui debuggers can handle it correctly. For example node-inspector based on DevTools.

@silverwind
Copy link
Contributor

@3y3 would something like this work for node-inspector?

console.groupCollapsed = function () {
  console.group.apply(console, arguments);
}

@3y3
Copy link

3y3 commented May 18, 2015

@silverwind , yes, this would work.

@imyller
Copy link
Member

imyller commented May 18, 2015

What about indents node would add to the output? node-inspector removes them and just marks the console message to a specific group/level?

@3y3
Copy link

3y3 commented May 18, 2015

node-inspector removes them and just marks the console message to a specific group/level?

node-inspector will remove them then (if) this feature will be implemented.

@3y3
Copy link

3y3 commented May 18, 2015

3y3 commented a minute ago

node-inspector removes them and just marks the console message to a specific group/level?
node-inspector will remove them then (if) this feature will be implemented.

I correct myself. Node Inspector will receive not formatted messages, in other words, he doesn't need to trim leading spaces.

@imyller
Copy link
Member

imyller commented May 18, 2015

Node Inspector will receive not formatted messages

Oh, I too forgot that node-inspector wraps the entire function call. No issues then.

@imyller
Copy link
Member

imyller commented May 18, 2015

I've opened a pull-request #1727 to implement this feature in core lib

@Fishrock123 Fishrock123 added the feature request Issues that request new features to be added to Node.js. label May 18, 2015
@Fishrock123 Fishrock123 removed the good first issue Issues that are suitable for first-time contributors. label Oct 7, 2015
@jasnell
Copy link
Member

jasnell commented Mar 22, 2016

Closing this one. This has come up several times and we keep landing on not pursuing this.

@silverwind silverwind reopened this Sep 20, 2016
@silverwind silverwind added the inspector Issues and PRs related to the V8 inspector protocol label Sep 20, 2016
@bmeck
Copy link
Member

bmeck commented Nov 17, 2016

This is fixed, re-open if anything needs changing.

@bmeck bmeck closed this as completed Nov 17, 2016
@SimenB
Copy link
Member

SimenB commented Nov 18, 2016

@bmeck Do you have a link to a PR/commit? Can't find it (and it's not in 7.1.0). https://github.com/nodejs/node/search?q=%22console.group%22
And console.js has no mention of it: https://github.com/nodejs/node/blob/master/lib/console.js

@bmeck
Copy link
Member

bmeck commented Nov 18, 2016

@SimenB oh interesting, it appears when --inspect is enabled (when I was checking) you get an entirely different console global. That seems like odd behavior / should not be the case.

@bmeck bmeck reopened this Nov 18, 2016
@SimenB
Copy link
Member

SimenB commented Nov 18, 2016

It's probably Chrome's console then? Yeah, that would be unexpected

@bmeck
Copy link
Member

bmeck commented Nov 18, 2016

@SimenB even in node's repl it is replaced, not chrome's,

v8::Local<v8::Object> V8Console::createConsole(
replaces what is in console.js

@Trott
Copy link
Member

Trott commented Jul 15, 2017

Implemented but it doesn't seem to actually do anything?

$ node -v
v8.1.4
$ node -e "console.log(console.group.toString())"
function group() { [native code] }
$ cat test.js
console.log("This is the outer level");
console.group();
console.log("Level 2");
console.group();
console.log("Level 3");
console.warn("More of level 3");
console.groupEnd();
console.log("Back to level 2");
console.groupEnd();
console.log("Back to the outer level");
$ node test.js
This is the outer level
Level 2
Level 3
More of level 3
Back to level 2
Back to the outer level
$ 

I would expect the groups to at least be indented.

@silverwind
Copy link
Contributor

silverwind commented Jul 16, 2017

Interesting, looks like a recent v8 update defined a number console methods that are available in Chrome, but because they aren't implemented in Node.js, they seem to be just noops. Maybe we should undefine them when not launched with --inspect so to not confuse users?

@TimothyGu
Copy link
Member

Maybe we should undefine them when not launched with --inspect so to not confuse users?

We cannot do that easily because we support opening inspector during runtime (https://nodejs.org/api/inspector.html#inspector_inspector_open_port_host_wait).

We should just implement group, groupCollapse, and groupEnd with indentation. It's not that difficult.

@Trott
Copy link
Member

Trott commented Aug 18, 2017

#14910 PR for the most minimal console.group() and console.groupEnd() implementation I could muster.

Trott added a commit to Trott/io.js that referenced this issue Aug 22, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time. (It lacks
the `label` argument to `console.group()` right now, for example. How to
handle `label`, or even whether to handle it,  may become
a bikeshed discussion. Landing a minimal implementation first avoids the
pitfall of that discussion or a similar discussion delaying the
implementation indefinitely.)

Refs: nodejs#12675
Fixes: nodejs#1716
@Trott Trott closed this as completed in c40229a Aug 24, 2017
addaleax pushed a commit to addaleax/ayo that referenced this issue Aug 25, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time.

`console.groupCollapsed()` is implemented as an alias for
`console.group()`.

PR-URL: nodejs/node#14910
Fixes: nodejs/node#1716
Ref: nodejs/node#12675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit to ayojs/ayo that referenced this issue Aug 28, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time.

`console.groupCollapsed()` is implemented as an alias for
`console.group()`.

PR-URL: nodejs/node#14910
Fixes: nodejs/node#1716
Ref: nodejs/node#12675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this issue Sep 10, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time.

`console.groupCollapsed()` is implemented as an alias for
`console.group()`.

PR-URL: #14910
Fixes: #1716
Ref: #12675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this issue Sep 11, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time.

`console.groupCollapsed()` is implemented as an alias for
`console.group()`.

PR-URL: #14910
Fixes: #1716
Ref: #12675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this issue Sep 11, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time.

`console.groupCollapsed()` is implemented as an alias for
`console.group()`.

PR-URL: #14910
Fixes: #1716
Ref: #12675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this issue Sep 12, 2017
Node.js exposes `console.group()` and `console.groupEnd()` via the
inspector. These functions have no apparent effect when called from
Node.js without the inspector. We cannot easily hide them when Node.js
is started without the inspector because we support opening the
inspector during runtime via `inspector.port()`.

Implement a minimal `console.group()`/`console.groupEnd()`. More
sophisticated implementations are possible, but they can be done in
userland and/or features can be added to this at a later time.

`console.groupCollapsed()` is implemented as an alias for
`console.group()`.

PR-URL: #14910
Fixes: #1716
Ref: #12675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.