From 4832c28dd2e46ba503cd5b7ad9da0b223bb0ef9d Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Thu, 3 Jan 2019 17:46:23 +0530 Subject: [PATCH] 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 --- js/log.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/log.js b/js/log.js index 4f82176b..c915301e 100644 --- a/js/log.js +++ b/js/log.js @@ -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);