1

Until recently I've used console.log extensively in Electron, both from code and monitoring results in the Developer Tools console, and also by typing console.log("something or other") directly in the Developer Tools console.

All of a sudden it's no longer working. Nothing happens when running console.log() from a JS script, and if I type console.log("test") in the Developer Tools console the response is "undefined". console.log by itself (no parentheses) shows ƒ (){} as opposed to function log() {[native code]}, which perhaps explains the lack of functionality?

Trying to figure out how that might have happened and how to resolve it -- did I accidentally click on some preference or setting somewhere? Quite the PITA to lose that.

WhatsYourFunction
  • 621
  • 1
  • 9
  • 25
  • It's possible to override `console.log` with some other function (e.g. an empty function to disable log output in production). Maybe an imported module does that? Try a log statement at the beginning of your renderer script, before importing stuff. – snwflk Feb 26 '22 at 13:55
  • You didn't accidently deselect the `Info` selection in the `Default levels` dropdown menu near the top right-hand corner of the DevTools window? If you did, you can just select `Default` from the dropdown list and it will reset the `Info`, `Warnings` and `Errors` logging levels. – midnight-coding Feb 27 '22 at 11:33
  • @midnight-coding thanks - That's the kind of thing I though I might have somehow accidentally clicked, but I'd checked those, and all is fine there. – WhatsYourFunction Feb 27 '22 at 14:36
  • @snwflk - Thanks Yes, I'm aware of that & checked the code for something that might have changed it. On further digging it turns out `console.info`, `console.error`, `console.warn` -- none of these work and all show the `ƒ (){}` as opposed to `function () {[native code]}` BUT `console.debug`, `console.dir`, and perhaps most interestingly `console.context().log()` all DO work just fine. That effectively solves the problem in my use case. But considering I don't use any of those others in my code, it leaves quite the mystery about what's going on. – WhatsYourFunction Feb 27 '22 at 14:48
  • Have you tried the suggestion to add a `console.log('test')` before any imports? If that works, you know something later in the renderer code causes the override. – snwflk Feb 27 '22 at 19:55
  • Tried that indeed. console.log is dead from the start. – WhatsYourFunction Mar 01 '22 at 20:30
  • This link ( https://stackoverflow.com/questions/31759367/using-console-log-in-electron-app ) suggests console.log might, by default, be logging to a terminal stdout whereas console.context().log() definitely logs a browser developer tools console. – WhatsYourFunction Mar 01 '22 at 20:54

1 Answers1

0

where console.log() stopped working

console.context().log() is the alternative command that so far has been working.

WhatsYourFunction
  • 621
  • 1
  • 9
  • 25