csepulv / electron-with-create-react-app

Sample Electron application using create-react-app
MIT License
831 stars 217 forks source link

logging from `electron-starter` #14

Closed gabrielmontagne closed 5 years ago

gabrielmontagne commented 6 years ago

Perhaps because it's run as a child process, logs in the electron-starter are not shown on the console from which the project is started.

As a workaround I am manually starting first the create react app bit, then, by hand, the electron npm script -- with the ELECTRON_START_URL prefix.

Is there a way for this solution to surface console.logs from that electron-starter. js file?

Thanks!

csepulv commented 6 years ago

Unfortunately I don't know. There isn't much going on in electron-starter.js, so I haven't had to do much with it, such as logging.

I've seen various discussions about logging and the main process; if you google 'electron main console.log' you can find various discussions on this. The use of create-react-app (it's dev server) might also be getting in the way.

You might try packages like electron-log, which could be used to capture/direct logging. (I haven't used it, but came across it when I tried to do a quick search for a way to set the console.log messages.

lildesert commented 5 years ago

Here's what you need to do if you want to print the child process logs

const electron = exec("yarn electron");
electron.stdout.on("data", function(data) {
  console.log("stdout: " + data.toString());
});

in electron-starter.js

Actually I just made a PR to fix this issue.

csepulv commented 5 years ago

Seems to work. I accepted/merged the PR. Thanks