Reputation: 4721
I have an electron app that run perfectly into a dev environment with logs engine that write into file (with winston.js).
The structure of the project is this :
When I run electron-builder for packaging my app I have this struture :
In dev environment I access to logs file with this winston config :
new winston.transports.File({filename: 'data/logs/error.log', level: 'error'})
But this specific path config only run into dev mode. And I don't find a good path for targetting the logs files in prod environment.
What kind of path I need to use in prod environment for targetting files out of Resources directory (or root of Contents directory installed application) ?
What is the best pratices for managing logs with electron app ?
Upvotes: 1
Views: 2186
Reputation: 2464
For getting the resources and extraFiles
paths in a packaged app as described in the electron-builder docs you can use process.resourcesPath
const getResourcesPath = () => {
return process.resourcesPath;
};
const getExtraFilesPath = () => {
return path.join(process.resourcesPath, '..'); // go up one directory
};
For logs, Electron provides a path for this purpose which you can check using app.getPath
app.getPath('logs');
By default, this will be ~/Library/Logs/YourAppName
on macOS, and inside the userData
directory on Linux and Windows
You can change this default path using app.setAppLogsPath
if needed
Most Electron apps store logs in the default location
Upvotes: 2