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

console.log does not log to the dev tools console window #11990

Closed
bughit opened this issue Feb 20, 2018 · 17 comments · Fixed by #25765
Closed

console.log does not log to the dev tools console window #11990

bughit opened this issue Feb 20, 2018 · 17 comments · Fixed by #25765

Comments

@bughit
Copy link
Contributor

bughit commented Feb 20, 2018

  • Electron version: debug version built from master (7e2f760)
  • Operating system: win7 sp1 x64

Expected behavior

node --inspect-brk -e console.log('hello') logs to stdout and the dev tools console
so one expects electron to do the same

Actual behavior

electron with attached dev tools only logs to stdout

How to reproduce

console_log.js with console.log('hello');
electron.exe --inspect-brk console_log.js

@bughit bughit changed the title console.log does not log to the the dev tools console window console.log does not log to the dev tools console window Feb 21, 2018
@bughit
Copy link
Contributor Author

bughit commented Feb 23, 2018

"dev tools" is referring to the external chrome dev tools inspecting/debugging the electron main process.

@natew
Copy link
Contributor

natew commented Jun 12, 2018

+1, seeing this as of 2.0, wasn't happening in 1.8.

@bughit
Copy link
Contributor Author

bughit commented Jul 16, 2018

@zcbenz

On windows, console.log is redirected to process.log

if (process.platform === 'win32') {
  // Redirect node's console to use our own implementations, since node can not
  // handle console output when running as GUI program.
  var consoleLog = function (...args) {
    return process.log(util.format(...args) + '\n')
  }

which is implemented in AtomBindings::Log

#if defined(OS_WIN)
    process.SetMethod("log", &AtomBindings::Log);
#endif

which only logs to stdout

// static
void AtomBindings::Log(const base::string16& message) {
  std::cout << message << std::flush;
}

so can't the new console.log simply call both, the orginal console.log and process.log?

if (process.platform === 'win32') {
  // Redirect node's console to use our own implementations, since node can not
  // handle console output when running as GUI program.
  const origLog = console.log
  var consoleLog = function (...args) {
    origLog.call(console, ...args);
    return process.log(util.format(...args) + '\n')
  }

@zcbenz
Copy link
Member

zcbenz commented Aug 22, 2018

@bughit The problem with original implementation is, it would throw exception when stdout is not available. We should probably find out which call is actually printing the message to devtools and then invoke it.

@bughit
Copy link
Contributor Author

bughit commented Aug 23, 2018

@zcbenz I actually got around to trying my suggestion a while ago and saw that it was double logging, though I did not see exceptions, should have posted that.

@natew
Copy link
Contributor

natew commented Sep 17, 2018

This is painful, how are people debugging electron apps without repl working? Any workarounds?

I tested in 1.8.8 and it's broken there too. It was working at some point, anyone know a version?

Edit: On OS X Mojave, tried 1.8.8, 2.0 latest and 3.0 latest beta.

@mb8z
Copy link

mb8z commented Nov 10, 2018

I have never experience this until today. What a weird behaviour :/

@noe132
Copy link

noe132 commented Dec 25, 2018

Any update on this? Is there any workaround?

@sofianguy
Copy link
Contributor

Thank you for taking the time to report this issue and helping to make Electron better.

The version of Electron you reported this on has been superseded by newer releases.

If you're still experiencing this issue in Electron v4.2.x or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.

I'm setting the blocked/need-info label for the above reasons. This issue will be closed 7 days from now if there is no response.

Thanks in advance! Your help is appreciated.

@sofianguy sofianguy added the blocked/need-info ❌ Cannot proceed without more information label Aug 9, 2019
@natew
Copy link
Contributor

natew commented Aug 9, 2019 via email

@jpoppe
Copy link

jpoppe commented Aug 9, 2019

It's also still not working on version 6 for me, bug seems obvious and is easy to replicate.

Update: I only see the Windows label, to clarify it also does not work on Linux distributions.

@bughit
Copy link
Contributor Author

bughit commented Aug 9, 2019

@sofianguy Does the author of the bug need to reply to clear this need-info?

Yes, it's still present in 6.

@sofianguy sofianguy added 6-0-x and removed blocked/need-info ❌ Cannot proceed without more information labels Aug 9, 2019
@sofianguy sofianguy added this to Unsorted Issues in 6.1.x Aug 9, 2019
@CynicalBusiness
Copy link

I can confirm this is happening in v6.0.x (namely v6.0.7) on Windows 10 (1809).

It also appears to not happen to console.info, but other console methods (like log, warn, and error) are afflicted. What makes that one special?

For example:

// index.js
console.log('log')
console.info('info')
.\node_modules\.bin\electron --inspect index.js
> 'info'

node --inspect index.js
> 'log'
> 'info'

Serves as a work-around I guess, but still annoying.

@ghost
Copy link

ghost commented May 14, 2020

Same. Electron version v8.2.5, Win7 64. console.info works, but console.log doesn't.
So the workaround for now is:

console.log(`shouldn't work`)
console.log = console.info;
console.log('should work')

@m4heshd
Copy link

m4heshd commented Jan 11, 2021

I'm on v11.1.1 and the issue is still here.

@MasterIO02
Copy link

Can confirm this issue is still here, but only on Windows for me, not on Linux. I can log nothing in the browser, no matter what I try with console.log, console.info, using '' instead of ``, the only thing that can log something for me on Windows is myConsole that logs in the nodejs process, but that's not what I want.

@deepak1556
Copy link
Member

@m4heshd for issue with Electron 11 please update to 11.2.0 which got fixed by #27102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
6.1.x
Unsorted Issues
Development

Successfully merging a pull request may close this issue.

12 participants