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

Programmatically print an object to the inspector console #21651

Closed
mcollina opened this issue Jul 4, 2018 · 6 comments
Closed

Programmatically print an object to the inspector console #21651

mcollina opened this issue Jul 4, 2018 · 6 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@mcollina
Copy link
Member

mcollina commented Jul 4, 2018

  • Version: master (and all releases that had the new inspector)
  • Platform: all
  • Subsystem: inspector, console

Recently I've seen a couple of requests to logging libraries to route logs to the inspector console. As far as I know, this is currently not possible using the current API.

Do you think it's worth adding an API to programmatically print object to the console? What would be needed to add it?

@mcollina mcollina added the feature request Issues that request new features to be added to Node.js. label Jul 4, 2018
@targos
Copy link
Member

targos commented Jul 4, 2018

Are you asking for a way to print only to the inspector console (avoid having the output in stdout)?

@mcollina
Copy link
Member Author

mcollina commented Jul 4, 2018

Yes, exactly. I think Node.js should provide a way for logging framework to send output there.

@targos
Copy link
Member

targos commented Jul 4, 2018

Sounds good to me.

The original console object is overwritten when Node bootstraps:

function setupGlobalConsole() {
const originalConsole = global.console;
const CJSModule = NativeModule.require('internal/modules/cjs/loader');
// Setup Node.js global.console.
const wrappedConsole = NativeModule.require('console');
Object.defineProperty(global, 'console', {
configurable: true,
enumerable: false,
value: wrappedConsole,
writable: true
});
setupInspector(originalConsole, wrappedConsole, CJSModule);
}

I suppose we could keep a reference to it and export it from a public module. Maybe require('console').inspector or require('inspector').console ?

@devsnek
Copy link
Member

devsnek commented Jul 4, 2018

inspector.console sounds good to me

@mcollina
Copy link
Member Author

mcollina commented Jul 4, 2018

I'm preparing a PR.

mcollina added a commit to mcollina/node that referenced this issue Jul 5, 2018
Adds require('inspector').console, mapping it to the original
global.console of V8. This enables applications to send messages to
the inspector console programmatically.

Fixes: nodejs#21651
@mcollina
Copy link
Member Author

mcollina commented Jul 6, 2018

Fixed in 19795d8

@mcollina mcollina closed this as completed Jul 6, 2018
mcollina added a commit that referenced this issue Jul 6, 2018
Adds require('inspector').console, mapping it to the original
global.console of V8. This enables applications to send messages to
the inspector console programmatically.

Fixes: #21651

PR-URL: #21659
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
targos pushed a commit that referenced this issue Jul 8, 2018
Adds require('inspector').console, mapping it to the original
global.console of V8. This enables applications to send messages to
the inspector console programmatically.

Fixes: #21651

PR-URL: #21659
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
targos pushed a commit that referenced this issue Jul 18, 2018
Adds require('inspector').console, mapping it to the original
global.console of V8. This enables applications to send messages to
the inspector console programmatically.

Fixes: #21651

PR-URL: #21659
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

3 participants