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

3

25

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

Gearing answered 14/12, 2016 at 11:1 Comment(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.Overpower
H
11

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.

Haye answered 27/1, 2017 at 13:24 Comment(4)
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.Gearing
Yep. You can use a logging package in electron to do the actual writing of log files to make it easier :)Haye
I cant find the log file/logs. can anyone please help ?Suzettesuzi
This landed in Electron 6. Maybe be relevant for people on newer projects. electronjs.org/docs/api/app#appsetapplogspathpathGeest
J
5

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

Jiles answered 9/3, 2023 at 14:31 Comment(1)
On macOS, in Finder, ~/Library is a hidden folder. Show hidden folders with cmd-shift-.Himmler
G
0

You can tell node to write stdout to a file like so: https://mcmap.net/q/109046/-configure-node-js-to-log-to-a-file-instead-of-the-console

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.

Goring answered 1/12, 2022 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.