Tieme
Tieme

Reputation: 65499

Where can I find the logs for my Electron app in production?

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..

Upvotes: 25

Views: 53740

Answers (3)

matthieu Bouamama
matthieu Bouamama

Reputation: 319

The default Electron log locations are:

  • 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

Upvotes: 6

Jordan
Jordan

Reputation: 4823

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.

Upvotes: 0

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.

Upvotes: 11

Related Questions