summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/app.js5
-rw-r--r--app/lib/backend.js27
-rw-r--r--app/lib/ipc.js3
-rw-r--r--app/main.js29
-rw-r--r--app/tilecache.sw.js2
-rw-r--r--package.json3
-rw-r--r--test/global.js6
7 files changed, 50 insertions, 25 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
+});
diff --git a/package.json b/package.json
index 7729b34a9a..8ad7abf859 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
"dependencies": {
"babel-runtime": "^6.22.0",
"cheap-ruler": "^2.4.1",
+ "electron-log": "^2.2.0",
"jsonrpc-lite": "^1.2.3",
"moment": "^2.17.1",
"react": "^15.4.2",
@@ -62,7 +63,7 @@
"scripts": {
"postinstall": "install-app-deps",
"develop": "npm run private:compile -- --source-maps true && npm run private:service-worker && run-p -r private:watch private:serve",
- "test": "electron-mocha -R spec --compilers js:babel-core/register test/*.spec.js test/**/*.spec.js",
+ "test": "electron-mocha -R spec --compilers js:babel-core/register test/global.js test/*.spec.js test/**/*.spec.js",
"lint": "eslint --no-ignore scripts app test *.js",
"docs": "esdoc",
"pack": "run-s private:clean private:compile private:service-worker private:build:all",
diff --git a/test/global.js b/test/global.js
new file mode 100644
index 0000000000..6653a4f8cb
--- /dev/null
+++ b/test/global.js
@@ -0,0 +1,6 @@
+import log from 'electron-log';
+
+before(() => {
+ log.transports.console.level = false;
+ log.transports.file.level = false;
+});