From 15f524d4aac75f692de27fc39df8d5665066a90d Mon Sep 17 00:00:00 2001 From: Gregor Herdmann Date: Thu, 21 Sep 2017 17:15:21 +0200 Subject: [PATCH] fix: Ensure ID before creating log (#961) --- electron/renderer/static/webview-preload.js | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/electron/renderer/static/webview-preload.js b/electron/renderer/static/webview-preload.js index 7f804a9d43a..f098deb6dd1 100644 --- a/electron/renderer/static/webview-preload.js +++ b/electron/renderer/static/webview-preload.js @@ -120,20 +120,23 @@ function replaceGoogleAuth() { function enableFileLogging() { const id = new URL(window.location).searchParams.get('id'); - const logName = require('../../js/config').CONSOLE_LOG; - const logFilePath = path.join(app.getPath('userData'), 'logs', id, logName); - fs.createFileSync(logFilePath); - - const logger = new winston.Logger(); - logger.add(winston.transports.File, { - filename: logFilePath, - handleExceptions: true, - }); - logger.info(pkg.productName, 'Version', pkg.version); + if (id) { + const logName = require('../../js/config').CONSOLE_LOG; + const logFilePath = path.join(app.getPath('userData'), 'logs', id, logName); + fs.createFileSync(logFilePath); + + const logger = new winston.Logger(); + logger.add(winston.transports.File, { + filename: logFilePath, + handleExceptions: true, + }); - // webapp uses global winston reference to define log level - global.winston = logger; + logger.info(pkg.productName, 'Version', pkg.version); + + // webapp uses global winston reference to define log level + global.winston = logger; + } } function reportWebappVersion() {