diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-04-12 20:01:22 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-04-18 13:15:22 +0200 |
| commit | ce0cce15281c19d7966b074ae32d9991fdcfc06b (patch) | |
| tree | 0982ae5aa8388fa7b81af520f46a87e20db7ee5b /app | |
| parent | e515cd8f97cc5597a870d0f776a1a1b4da52da61 (diff) | |
| download | mullvadvpn-ce0cce15281c19d7966b074ae32d9991fdcfc06b.tar.xz mullvadvpn-ce0cce15281c19d7966b074ae32d9991fdcfc06b.zip | |
Use electron-log instead of console.log
Diffstat (limited to 'app')
| -rw-r--r-- | app/app.js | 5 | ||||
| -rw-r--r-- | app/lib/backend.js | 27 | ||||
| -rw-r--r-- | app/lib/ipc.js | 3 | ||||
| -rw-r--r-- | app/main.js | 29 | ||||
| -rw-r--r-- | app/tilecache.sw.js | 2 |
5 files changed, 42 insertions, 24 deletions
diff --git a/app/app.js b/app/app.js index 143a817cef..7ce2e3418d 100644 --- a/app/app.js +++ b/app/app.js @@ -5,6 +5,7 @@ import { Provider } from 'react-redux'; import { Router, createMemoryHistory } from 'react-router'; import { syncHistoryWithStore } from 'react-router-redux'; import { webFrame, ipcRenderer } from 'electron'; +import log from 'electron-log'; import makeRoutes from './routes'; import configureStore from './store'; import userActions from './actions/user'; @@ -101,9 +102,9 @@ webFrame.setZoomLevelLimits(1, 1); if ('serviceWorker' in navigator) { navigator.serviceWorker.register(path.join(__dirname, 'tilecache.sw.js')) .then((registration) => { - console.log('ServiceWorker registration successful with scope: ', registration.scope); + log.info('ServiceWorker registration successful with scope: ', registration.scope); }).catch((err) => { - console.log('ServiceWorker registration failed: ', err); + log.info('ServiceWorker registration failed: ', err); }); } diff --git a/app/lib/backend.js b/app/lib/backend.js index d259f78318..38adc6cf14 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -1,4 +1,5 @@ import moment from 'moment'; +import log from 'electron-log'; import Enum from './enum'; import { EventEmitter } from 'events'; import { servers } from '../config'; @@ -173,7 +174,7 @@ export default class Backend extends EventEmitter { } setLocation(loc) { - console.log('Got connection info to backend', loc); + log.info('Got connection info to backend', loc); this._ipc = new Ipc(loc); this._registerIpcListeners(); @@ -193,20 +194,20 @@ export default class Backend extends EventEmitter { } sync() { - console.log('Syncing with the backend...'); + log.info('Syncing with the backend...'); this._ipc.send('get_connection') .then( connectionInfo => { - console.log('Got connection info', connectionInfo); + log.info('Got connection info', connectionInfo); this.emit(Backend.EventType.updatedIp, connectionInfo.ip); }) .catch(e => { - console.log('Failed syncing with the backend', e); + log.info('Failed syncing with the backend', e); }); this._ipc.send('get_location') .then(location => { - console.log('Got location', location); + log.info('Got location', location); const newLocation = { location: location.latlong, country: location.country, @@ -215,7 +216,7 @@ export default class Backend extends EventEmitter { this.emit(Backend.EventType.updatedLocation, newLocation, null); }) .catch(e => { - console.log('Failed getting new location', e); + log.info('Failed getting new location', e); }); } @@ -280,7 +281,7 @@ export default class Backend extends EventEmitter { * @memberOf Backend */ login(account) { - console.log('Attempting to login with account number', account); + log.info('Attempting to login with account number', account); this._paidUntil = null; // emit: logging in @@ -289,7 +290,7 @@ export default class Backend extends EventEmitter { this._ipc.send('login', { accountNumber: account, }).then(response => { - console.log('Successfully logged in', response); + log.info('Successfully logged in', response); this._paidUntil = response.paidUntil; this.emit(Backend.EventType.login, response, undefined); }).catch(e => { @@ -318,7 +319,7 @@ export default class Backend extends EventEmitter { this.disconnect(); }) .catch(e => { - console.log('Failed to logout', e); + log.info('Failed to logout', e); }); } @@ -346,7 +347,7 @@ export default class Backend extends EventEmitter { this.sync(); // TODO: This is a pooooooor way of updating the location and the IP and stuff }) .catch(e => { - console.log('Failed connecting to', addr, e); + log.info('Failed connecting to', addr, e); this.emit(Backend.EventType.connect, undefined, e); }); } @@ -361,7 +362,7 @@ export default class Backend extends EventEmitter { // @TODO: Failure modes this._ipc.send('cancelConnection') .catch(e => { - console.log('Failed cancelling connection', e); + log.info('Failed cancelling connection', e); }); // @TODO: Failure modes @@ -372,7 +373,7 @@ export default class Backend extends EventEmitter { this.sync(); // TODO: This is a pooooooor way of updating the location and the IP and stuff }) .catch(e => { - console.log('Failed to disconnect', e); + log.info('Failed to disconnect', e); }); } @@ -404,7 +405,7 @@ export default class Backend extends EventEmitter { _registerIpcListeners() { this._ipc.on('connection-info', (newConnectionInfo) => { - console.log('Got new connection info from backend', newConnectionInfo); + log.info('Got new connection info from backend', newConnectionInfo); }); } } diff --git a/app/lib/ipc.js b/app/lib/ipc.js index 0be6341cf6..570abc2cec 100644 --- a/app/lib/ipc.js +++ b/app/lib/ipc.js @@ -1,5 +1,6 @@ import jsonrpc from 'jsonrpc-lite'; import uuid from 'uuid'; +import log from 'electron-log'; export default class Ipc { @@ -8,7 +9,7 @@ export default class Ipc { } on(event/*, listener*/) { - console.log('Adding a listener to', event); + log.info('Adding a listener to', event); } send(action, data) { diff --git a/app/main.js b/app/main.js index d57aea2a1f..42321be78c 100644 --- a/app/main.js +++ b/app/main.js @@ -1,6 +1,7 @@ import path from 'path'; import fs from 'fs'; import sudo from 'sudo-prompt'; +import log from 'electron-log'; import { app, BrowserWindow, ipcMain, Tray, Menu, nativeImage } from 'electron'; import TrayIconManager from './lib/tray-icon-manager'; @@ -18,6 +19,20 @@ ipcMain.on('on-browser-window-ready', () => { sendBackendInfo(); }); +const configureLogger = () => { + + if (isDevelopment) { + log.transports.console.level = 'debug'; + + // Disable log file in development + log.transports.file.level = false; + } else { + log.transports.console.level = 'info'; + log.transports.file.level = 'info'; + } +}; +configureLogger(); + const installDevTools = async () => { const installer = require('electron-devtools-installer'); const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']; @@ -26,7 +41,7 @@ const installDevTools = async () => { try { await installer.default(installer[name], forceDownload); } catch (e) { - console.log(`Error installing ${name} extension: ${e.message}`); + log.info(`Error installing ${name} extension: ${e.message}`); } } }; @@ -198,14 +213,14 @@ app.on('ready', async () => { const sendBackendInfo = () => { const file = './.ipc_connection_info'; - console.log('reading the ipc connection info from', file); + log.info('reading the ipc connection info from', file); fs.readFile(file, 'utf8', function (err,data) { if (err) { - return console.log('Could not find backend connection info', err); + return log.info('Could not find backend connection info', err); } - console.log('Read IPC connection info', data); + log.info('Read IPC connection info', data); window.webContents.send('backend-info', { addr: data, }); @@ -214,16 +229,16 @@ const sendBackendInfo = () => { const startBackend = () => { const pathToBackend = path.resolve(process.env.MULLVAD_BACKEND || '../talpid_core/target/debug/talpid_daemon'); - console.log('Starting the mullvad backend at', pathToBackend); + log.info('Starting the mullvad backend at', pathToBackend); const options = { name: 'mullvad backend', }; sudo.exec(pathToBackend, options, (err) => { if (err) { - console.log('Backend exited with error', err); + log.info('Backend exited with error', err); } else { - console.log('Backend exited'); + log.info('Backend exited'); } }); }; diff --git a/app/tilecache.sw.js b/app/tilecache.sw.js index 4a3721216b..15ec8f9493 100644 --- a/app/tilecache.sw.js +++ b/app/tilecache.sw.js @@ -24,4 +24,4 @@ this.addEventListener('fetch', function(event) { }) ); } -});
\ No newline at end of file +}); |
