diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-18 08:03:50 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-18 08:03:50 -0300 |
| commit | 2c4e1d4b30216fd349930089df7d92a3d1268592 (patch) | |
| tree | 3bbf676d3e3574ed221575b595f6f9f4613a2a9d /app | |
| parent | 453c0d304ecc8732692c56238be1f6763519f7c4 (diff) | |
| parent | 6f33d5b51076d51c5576b5f34730da400a79fa61 (diff) | |
| download | mullvadvpn-2c4e1d4b30216fd349930089df7d92a3d1268592.tar.xz mullvadvpn-2c4e1d4b30216fd349930089df7d92a3d1268592.zip | |
Merge branch 'collect-logs-in-problem-report'
Diffstat (limited to 'app')
| -rw-r--r-- | app/main.js | 93 |
1 files changed, 38 insertions, 55 deletions
diff --git a/app/main.js b/app/main.js index 313315e37a..9c4d66f0d7 100644 --- a/app/main.js +++ b/app/main.js @@ -26,7 +26,7 @@ let browserWindowReady = false; const appDelegate = { _window: (null: ?BrowserWindow), _tray: (null: ?Tray), - _logFileLocation: '', + _logFilePath: '', _readyToQuit: false, connectionFilePollInterval: (null: ?IntervalID), @@ -34,7 +34,6 @@ const appDelegate = { // Override userData path, i.e on macOS: ~/Library/Application Support/Mullvad VPN app.setPath('userData', path.join(app.getPath('appData'), appDirectoryName)); - appDelegate._logFileLocation = appDelegate._getLogsDirectory(); appDelegate._initLogging(); log.info('Running version', version); @@ -45,7 +44,11 @@ const appDelegate = { _initLogging: () => { + const logDirectory = appDelegate._getLogsDirectory(); const format = '[{y}-{m}-{d} {h}:{i}:{s}.{ms}][{level}] {text}'; + + appDelegate._logFilePath = path.join(logDirectory, 'frontend.log'); + log.transports.console.format = format; log.transports.file.format = format; if (isDevelopment) { @@ -56,11 +59,11 @@ const appDelegate = { } else { log.transports.console.level = 'debug'; log.transports.file.level = 'debug'; - log.transports.file.file = path.join(appDelegate._logFileLocation, 'frontend.log'); + log.transports.file.file = appDelegate._logFilePath; } // create log folder - mkdirp.sync(appDelegate._logFileLocation); + mkdirp.sync(logDirectory); }, // Returns platform specific logs folder for application @@ -72,31 +75,13 @@ const appDelegate = { case 'darwin': // macOS: ~/Library/Logs/{appname} return path.join(app.getPath('home'), 'Library/Logs', appDirectoryName); - case 'win32': - // Windows: %ALLUSERSPROFILE%\{appname} - return appDelegate._getSharedDataDirectory(); default: + // Windows: %APPDATA%\{appname}\logs // Linux: ~/.config/{appname}/logs return path.join(app.getPath('userData'), 'logs'); } }, - _getSharedDataDirectory: () => { - switch(process.platform) { - case 'win32': { - // Windows: %ALLUSERSPROFILE%\{appname} - let programDataDirectory = process.env.ALLUSERSPROFILE; - if (typeof programDataDirectory === 'undefined' || programDataDirectory === null) { - throw new Error('Missing %ALLUSERSPROFILE% environment variable'); - } else { - return path.join(programDataDirectory, appDirectoryName); - } - } - default: - throw new Error(`No shared data directory on platform: ${process.platform}`); - } - }, - onTunnelShutdown: (isTunnelDown: boolean) => { appDelegate._readyToQuit = isTunnelDown; app.quit(); @@ -124,40 +109,30 @@ const appDelegate = { }); ipcMain.on('collect-logs', (event, id, toRedact) => { - log.info('Collecting logs in', appDelegate._logFileLocation); - fs.readdir(appDelegate._logFileLocation, (err, files) => { - if (err) { - event.sender.send('collect-logs-reply', id, err); - return; - } - - const logFiles = files.filter(file => file.endsWith('.log')) - .map(f => path.join(appDelegate._logFileLocation, f)); - const reportPath = path.join(app.getPath('temp'), uuid.v4() + '.log'); + const reportPath = path.join(app.getPath('temp'), uuid.v4() + '.log'); - const binPath = resolveBin('problem-report'); - let args = [ - 'collect', - '--output', reportPath, - ]; + const binPath = resolveBin('problem-report'); + let args = [ + 'collect', + '--output', reportPath, + ]; - if (toRedact.length > 0) { - args = args.concat([ - '--redact', ...toRedact, - '--', - ]); - } + if (toRedact.length > 0) { + args = args.concat([ + '--redact', ...toRedact, + '--', + ]); + } - args = args.concat(logFiles); + args = args.concat([appDelegate._logFilePath]); - execFile(binPath, args, {windowsHide: true}, (err) => { - if (err) { - event.sender.send('collect-logs-reply', id, err); - } else { - log.debug('Report written to', reportPath); - event.sender.send('collect-logs-reply', id, null, reportPath); - } - }); + execFile(binPath, args, {windowsHide: true}, (err) => { + if (err) { + event.sender.send('collect-logs-reply', id, err); + } else { + log.debug('Report written to', reportPath); + event.sender.send('collect-logs-reply', id, null, reportPath); + } }); }); @@ -184,8 +159,16 @@ const appDelegate = { const rpcAddressFileName = '.mullvad_rpc_address'; switch(process.platform) { - case 'win32': - return path.join(appDelegate._getSharedDataDirectory(), rpcAddressFileName); + case 'win32': { + // Windows: %ALLUSERSPROFILE%\{appname} + let programDataDirectory = process.env.ALLUSERSPROFILE; + if (typeof programDataDirectory === 'undefined' || programDataDirectory === null) { + throw new Error('Missing %ALLUSERSPROFILE% environment variable'); + } else { + let appDataDirectory = path.join(programDataDirectory, appDirectoryName); + return path.join(appDataDirectory, rpcAddressFileName); + } + } default: return path.join(getSystemTemporaryDirectory(), rpcAddressFileName); } |
