summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-01-12 13:29:33 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-01-15 13:32:09 +0100
commitef332247aa3408b2af862340cf3fe1ae4ee5054a (patch)
tree6a4680d9ad599861246053404211ec8b6d5675c5 /gui/src/main
parentfd02a14f3fad35f49cfd7b9deb3aae02fcf9dda2 (diff)
downloadmullvadvpn-ef332247aa3408b2af862340cf3fe1ae4ee5054a.tar.xz
mullvadvpn-ef332247aa3408b2af862340cf3fe1ae4ee5054a.zip
Use new logger
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/account-data-cache.ts2
-rw-r--r--gui/src/main/autostart.ts2
-rw-r--r--gui/src/main/daemon-rpc.ts2
-rw-r--r--gui/src/main/gui-settings.ts2
-rw-r--r--gui/src/main/index.ts58
-rw-r--r--gui/src/main/linux-desktop-entry.ts2
-rw-r--r--gui/src/main/notification-controller.ts2
7 files changed, 40 insertions, 30 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts
index 5c178e83a6..a03728e004 100644
--- a/gui/src/main/account-data-cache.ts
+++ b/gui/src/main/account-data-cache.ts
@@ -1,7 +1,7 @@
-import log from 'electron-log';
import moment from 'moment';
import { hasExpired } from '../shared/account-expiry';
import { AccountToken, IAccountData } from '../shared/daemon-rpc-types';
+import log from '../shared/logging';
import consumePromise from '../shared/promise';
import { Scheduler } from '../shared/scheduler';
import { InvalidAccountError } from './errors';
diff --git a/gui/src/main/autostart.ts b/gui/src/main/autostart.ts
index a42691550c..f5369b6723 100644
--- a/gui/src/main/autostart.ts
+++ b/gui/src/main/autostart.ts
@@ -1,8 +1,8 @@
import { app } from 'electron';
-import log from 'electron-log';
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
+import log from '../shared/logging';
const DESKTOP_FILE_NAME = 'mullvad-vpn.desktop';
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index 7f9e6d629b..9be0fc6870 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -4,7 +4,6 @@ import {
StringValue,
UInt32Value,
} from 'google-protobuf/google/protobuf/wrappers_pb.js';
-import log from 'electron-log';
import { Empty } from 'google-protobuf/google/protobuf/empty_pb.js';
import { promisify } from 'util';
import {
@@ -50,6 +49,7 @@ import {
TunnelProtocol,
IDnsOptions,
} from '../shared/daemon-rpc-types';
+import log from '../shared/logging';
import * as managementInterface from './management_interface/management_interface_grpc_pb';
import * as grpcTypes from './management_interface/management_interface_pb';
diff --git a/gui/src/main/gui-settings.ts b/gui/src/main/gui-settings.ts
index e7d8a47cf1..54b51116cd 100644
--- a/gui/src/main/gui-settings.ts
+++ b/gui/src/main/gui-settings.ts
@@ -1,8 +1,8 @@
import { app } from 'electron';
-import log from 'electron-log';
import * as fs from 'fs';
import * as path from 'path';
import { IGuiSettingsState, SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-settings-state';
+import log from '../shared/logging';
const settingsSchema = {
preferredLocale: 'string',
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index efef48e033..402a0a35cb 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -10,8 +10,6 @@ import {
shell,
Tray,
} from 'electron';
-import log from 'electron-log';
-import mkdirp from 'mkdirp';
import moment from 'moment';
import * as path from 'path';
import { sprintf } from 'sprintf-js';
@@ -39,14 +37,8 @@ import {
import { loadTranslations, messages } from '../shared/gettext';
import { SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-settings-state';
import { IpcMainEventChannel } from '../shared/ipc-event-channel';
-import {
- backupLogFile,
- cleanUpLogDirectory,
- getLogsDirectory,
- getMainLogFile,
- getRendererLogFile,
- setupLogging,
-} from '../shared/logging';
+import log, { ConsoleOutput, Logger } from '../shared/logging';
+import { LogLevel } from '../shared/logging-types';
import {
AccountExpiredNotificationProvider,
CloseToAccountExpiryNotificationProvider,
@@ -63,6 +55,16 @@ import { InvalidAccountError } from './errors';
import Expectation from './expectation';
import GuiSettings from './gui-settings';
import { getAppIcon } from './linux-desktop-entry';
+import {
+ backupLogFile,
+ cleanUpLogDirectory,
+ createLoggingDirectory,
+ FileOutput,
+ getMainLogPath,
+ getRendererLogPath,
+ IpcInput,
+ OLD_LOG_FILES,
+} from './logging';
import NotificationController from './notification-controller';
import { resolveBin } from './proc';
import ReconnectionBackoff from './reconnection-backoff';
@@ -201,6 +203,8 @@ class ApplicationMain {
private autoConnectOnWireguardKeyEvent = false;
private autoConnectFallbackScheduler = new Scheduler();
+ private rendererLog?: Logger;
+
public run() {
// Remove window animations to combat window flickering when opening window. Can be removed when
// this issue has been resolved: https://github.com/electron/electron/issues/12130
@@ -252,28 +256,35 @@ class ApplicationMain {
if (appDataDir) {
app.setPath('appData', appDataDir);
app.setPath('userData', path.join(appDataDir, app.name));
+ app.setPath('logs', path.join(appDataDir, app.name, 'logs'));
} else {
throw new Error('Missing %LOCALAPPDATA% environment variable');
}
+ } else if (process.platform === 'linux') {
+ const userDataDir = app.getPath('userData');
+ app.setPath('logs', path.join(userDataDir, 'logs'));
}
}
private initLogging() {
- const logDirectory = getLogsDirectory();
- const mainLogFile = getMainLogFile();
- const logFiles = [mainLogFile, getRendererLogFile()];
+ const mainLogPath = getMainLogPath();
+ const rendererLogPath = getRendererLogPath();
if (process.env.NODE_ENV !== 'development') {
- // Ensure log directory exists
- mkdirp.sync(logDirectory);
+ createLoggingDirectory();
+ cleanUpLogDirectory(OLD_LOG_FILES);
- for (const logFile of logFiles) {
- backupLogFile(logFile);
- }
+ backupLogFile(mainLogPath);
+ backupLogFile(rendererLogPath);
+
+ log.addOutput(new FileOutput(LogLevel.debug, mainLogPath));
+
+ this.rendererLog = new Logger();
+ this.rendererLog.addInput(new IpcInput());
+ this.rendererLog.addOutput(new FileOutput(LogLevel.debug, rendererLogPath));
}
- cleanUpLogDirectory();
- setupLogging(mainLogFile);
+ log.addOutput(new ConsoleOutput(LogLevel.debug));
}
private onActivate = () => {
@@ -340,6 +351,9 @@ class ApplicationMain {
}
this.daemonRpc.disconnect();
+
+ log.dispose();
+ this.rendererLog?.dispose();
}
private detectLocale(): string {
@@ -1151,10 +1165,6 @@ class ApplicationMain {
IpcMainEventChannel.app.handleOpenUrl((url) => shell.openExternal(url));
IpcMainEventChannel.app.handleOpenPath((path) => shell.openPath(path));
IpcMainEventChannel.app.handleShowOpenDialog((options) => dialog.showOpenDialog(options));
-
- IpcMainEventChannel.logging.handleLog(({ level, data }) =>
- this.rendererLog?.log(LogLevels[level], ...data),
- );
}
private async createNewAccount(): Promise<string> {
diff --git a/gui/src/main/linux-desktop-entry.ts b/gui/src/main/linux-desktop-entry.ts
index 02edd8eb0f..dc1ae0e57b 100644
--- a/gui/src/main/linux-desktop-entry.ts
+++ b/gui/src/main/linux-desktop-entry.ts
@@ -1,8 +1,8 @@
import child_process from 'child_process';
-import log from 'electron-log';
import fs from 'fs';
import path from 'path';
import { ILinuxApplication } from '../shared/application-types';
+import log from '../shared/logging';
type DirectoryDescription = string | RegExp;
diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts
index 95c1216b72..17343837d4 100644
--- a/gui/src/main/notification-controller.ts
+++ b/gui/src/main/notification-controller.ts
@@ -1,8 +1,8 @@
import { app, nativeImage, NativeImage, Notification } from 'electron';
-import log from 'electron-log';
import os from 'os';
import path from 'path';
import { TunnelState } from '../shared/daemon-rpc-types';
+import log from '../shared/logging';
import {
ConnectedNotificationProvider,
ConnectingNotificationProvider,