ELECTRON-839: add logic to set custom logs folder (#541)

- To gather data from multiple instances, sometimes, we would need to have different logs folder for different instances. We add support for setting custom logs folder via command line with this change
This commit is contained in:
Vishwas Shashidhar 2019-01-03 17:46:23 +05:30 committed by GitHub
parent b597c00ea6
commit 4832c28dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@
const fs = require('fs');
const util = require('util');
const {app} = require('electron');
const { app } = require('electron');
const path = require('path');
const getCmdLineArg = require('./utils/getCmdLineArg.js');
const logLevels = require('./enums/logLevels.js');
@ -105,7 +105,15 @@ let loggerInstance = new Logger();
* Initializes the electron logger for local logging
*/
function initializeLocalLogger() {
// eslint-disable-next-line global-require
// If the user has specified a custom log path use it.
let customLogPathArg = getCmdLineArg(process.argv, '--logPath=', false);
let customLogsFolder = customLogPathArg && customLogPathArg.substring(customLogPathArg.indexOf('=') + 1);
if (customLogsFolder && fs.existsSync(customLogsFolder)) {
app.setPath('logs', customLogsFolder);
}
// eslint-disable-next-line global-require
electronLog = require('electron-log');
const logPath = app.getPath('logs');
cleanupOldLogs(logPath);