24

I've built an app with Electron and used Electron-Builder to create a Squirrel windows installer and updater. It all works great but I'm having trouble debugging the production version of my app.

Are the logs created by a console.log written somewhere on disk when using the production version? If so, where can I find them? Or are those all removed when compiling the executable? There must be some kind of log file for my app right?

I've found the SquirrelSetupLog in C:\Users\Tieme\AppData\Local\MyApp\SquirrelSetupLog but that's not enough for debugging my production-only problem.


Just came across electron-log. That could work if regular console logs are indeed not written to disk somewhere..

Tieme
  • 62,602
  • 20
  • 102
  • 156
  • 1
    Adding this as a comment rather than full answer, as this is not an answer to saving the log statements to disk, but still might help someone... If you are just wanting to view the `console.log` statements in real time when executing the built exe (like you do when running `npm start`), if you are on Windows, call the app executable from cmd using `start "" yourapp.exe` - you will be able to see the console.log statements from main.js on the cmd. – bikz Oct 01 '22 at 16:31

3 Answers3

10

If you mean console from within the webapp, then this applies :)

You need to make a callback for this to work. Read more about them here: http://electron.atom.io/docs/api/remote/

Here is a short example:

In a file next to your electron main.js, named logger.js, add this code:

exports.log = (entry) => {
    console.log(entry);
}

And then in your webapp, use this to call this log method callback:

// This line gets the code from the newly created file logger.js
const logger = require('electron').remote.require('./logger');

// This line calls the function exports.log from the logger.js file, but
// this happens in the context of the electron app, so from here you can 
// see it in the console when running the electron app or write to disk.
logger.log('Woohoo!');

You might also want to have a look at https://www.npmjs.com/package/electron-log for "better" logging and writing to disk. But you always need to use callbacks.

  • Yeah so that means that you will have to provide your own way to write those logs to disk right? I get it. Just hoped output from console.log would be written to disk automatically somewhere. electron-log looks good. Thanks. – Tieme Jan 27 '17 at 13:47
  • Yep. You can use a logging package in electron to do the actual writing of log files to make it easier :) – Martin Ingvar Kofoed Jensen Jan 30 '17 at 08:49
  • 1
    I cant find the log file/logs. can anyone please help ? – chetan Oct 03 '18 at 12:41
  • 1
    This landed in Electron 6. Maybe be relevant for people on newer projects. https://electronjs.org/docs/api/app#appsetapplogspathpath – mmartinson Sep 06 '19 at 15:23
0

You can tell node to write stdout to a file like so: https://stackoverflow.com/a/33898010/4418836

The exe output by Squirrel is an installer - not the application. As you mentioned, it will put your actual app (after installation) in C:\Users\YOUR_NAME\AppData\Local\YOUR_APP.

So when you run your exe, the current working directory will be the AppData\Local directory (not the directory that you ran the installer from).

So after you have node output your stdout to a file, look in that directory for the logs.

Jordan
  • 3,813
  • 4
  • 24
  • 33
0

As electron log said default location for log file is:

  • on Linux: ~/.config/{app name}/logs/main.log
  • on macOS: ~/Library/Logs/{app name}/main.log
  • on Windows: %USERPROFILE%\AppData\Roaming{app name}\logs\main.log

reference: https://www.npmjs.com/package/electron-log