Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Update electron-log and fix renderer logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wschella committed Feb 17, 2019
1 parent 2891a7b commit b1de2a7
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 28 deletions.
10 changes: 5 additions & 5 deletions planetwars/client/app/main_process.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as log from 'electron-log';
import { app } from 'electron';

import * as main from './main';
import * as process from './process';

// TODO: Check all libraries mentioned here below
// https://github.com/sindresorhus/electron-util
Expand All @@ -15,24 +15,24 @@ import * as main from './main';
*/
async function main_process() {
// First thing to do is setting up logging
main.setupLogging();
process.shared.setupLogging();

// Log this only after log is setup to respect log policy
log.verbose("[STARTUP] Main process started.");

// Dirty global main window var, it seems to be the way to go for electron
const windowManager = new main.WindowManager({
const windowManager = new process.main.WindowManager({
mainContentURL: `file://${__dirname}/index.html`,
});

// Bind listeners (close, certificate-errors, etc...)
main.configureAppListeners(app, windowManager);
process.main.configureAppListeners(app, windowManager);

// When app is ready, spawn the (main window) browser window
await app.whenReady();
try {
windowManager.spawnMainWindow();
main.installExtensions()
process.main.installExtensions()
.catch((_err) => log.error('[STARTUP] Failed to install all extensions'));
} catch (err) {
log.error("[STARTUP] [FATAL] Failed to create browser window!", err, err.stack);
Expand Down
7 changes: 7 additions & 0 deletions planetwars/client/app/process/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as main from './main';
import * as shared from './shared';

export {
main,
shared,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './logging';
export * from './app_listeners';
export * from './window';
export * from './menu';
Expand Down
1 change: 1 addition & 0 deletions planetwars/client/app/process/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './logging';
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,41 @@ import * as log from 'electron-log';
* configuration.
*/
export function setupLogging() {
const { file, rendererConsole, logS } = log.transports;
const mainConsole = log.transports.console;
const { file, console: processConsole, remote } = log.transports;
// const mainConsole = log.transports.console;

// In dev, set log level to debug for all transports (except remote)
if (process.env.NODE_ENV === 'development') {
rendererConsole.level = "debug";
mainConsole.level = "debug";
// rendererConsole.level = "debug";
// mainConsole.level = "debug";
processConsole.level = "debug";
file.level = "debug";
logS.level = false;
remote.level = false;

// In prod, set log level to verbose for all transports (except remote)
} else {
rendererConsole.level = "verbose";
mainConsole.level = "verbose";
// rendererConsole.level = "verbose";
// mainConsole.level = "verbose";
processConsole.level = "verbose";
file.level = "info";
logS.level = false; // TODO: Would be cool to have a Sentry endpoint here
remote.level = false; // TODO: Would be cool to have a Sentry endpoint here
}

// Set log level for all transports
if (process.env.BB_LOG_LEVEL) {
setLogLevelFromEnv(rendererConsole, process.env.BB_LOG_LEVEL);
setLogLevelFromEnv(mainConsole, process.env.BB_LOG_LEVEL);
// setLogLevelFromEnv(rendererConsole, process.env.BB_LOG_LEVEL);
// setLogLevelFromEnv(mainConsole, process.env.BB_LOG_LEVEL);
setLogLevelFromEnv(processConsole, process.env.BB_LOG_LEVEL);
setLogLevelFromEnv(file, process.env.BB_LOG_LEVEL);
setLogLevelFromEnv(logS, process.env.BB_LOG_LEVEL);
setLogLevelFromEnv(remote, process.env.BB_LOG_LEVEL);
}

// Allow specific transport log levels to be controlled with env vars;
setLogLevelFromEnv(rendererConsole, process.env.BB_LOG_LEVEL_CONSOLE);
setLogLevelFromEnv(mainConsole, process.env.BB_LOG_LEVEL_WEB);
// setLogLevelFromEnv(rendererConsole, process.env.BB_LOG_LEVEL_CONSOLE);
// setLogLevelFromEnv(mainConsole!, process.env.BB_LOG_LEVEL_WEB);
setLogLevelFromEnv(processConsole, process.env.BB_LOG_LEVEL_CONSOLE);
setLogLevelFromEnv(file, process.env.BB_LOG_LEVEL_FILE);
setLogLevelFromEnv(logS, process.env.BB_LOG_LEVEL_REMOTE);
setLogLevelFromEnv(remote, process.env.BB_LOG_LEVEL_REMOTE);

log.debug("[STARTUP] Logging configured");
log.debug("[STARTUP] Debug logging main process activated");
Expand All @@ -50,7 +54,7 @@ function setLogLevelFromEnv(transport: log.ITransport, envVar: string | undefine
return;
}
if (logLevels.includes(envVar)) {
transport.level = envVar as log.LevelOption;
transport.level = envVar as log.ILevelOption;
return;
}
}
Expand Down
8 changes: 7 additions & 1 deletion planetwars/client/app/render_process.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import log from 'electron-log';
import * as log from 'electron-log';

// https://github.com/electron-userland/electron-webpack/issues/59#issuecomment-347070990
import 'react-hot-loader/patch';
Expand All @@ -15,12 +15,18 @@ import { rootSaga } from './sagas';
import { bindToStore } from './database/Database';
import { initializeDirs, populateMaps, populateBots } from './utils/Setup';

import * as process from './process';

import './styles/app.global.scss';
import './styles/lib.global.scss';

export let store: any;

async function render_process() {
// First thing we do is setup logging
process.shared.setupLogging();

// Log this only after log is setup to respect log policy
log.verbose('[STARTUP] Renderer process started');

// tslint:disable-next-line:no-var-requires
Expand Down
2 changes: 1 addition & 1 deletion planetwars/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"d3": "^5.5.0",
"electron-context-menu": "^0.11.0",
"electron-debug": "^2.0.0",
"electron-log": "^2.2.17",
"electron-log": "^3.0.1",
"electron-updater": "4.0.6",
"electron-window-state": "^5.0.3",
"font-awesome": "^4.7.0",
Expand Down
10 changes: 5 additions & 5 deletions planetwars/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2472,10 +2472,10 @@ electron-localshortcut@^3.0.0:
keyboardevent-from-electron-accelerator "^1.1.0"
keyboardevents-areequal "^0.2.1"

electron-log@^2.2.17:
version "2.2.17"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-2.2.17.tgz#e71e2ebb949fc96ded7cdb99eeee7202e48981d2"
integrity sha512-v+Af5W5z99ehhaLOfE9eTSXUwjzh2wFlQjz51dvkZ6ZIrET6OB/zAZPvsuwT6tm3t5x+M1r+Ed3U3xtPZYAyuQ==
electron-log@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-3.0.1.tgz#5c60913e8ae1a8645560eea8b3c47c60d101e797"
integrity sha512-bomFcrYvkEXj0H00T5GjBee50TBA/VwdoDFpPQ2jz3LDGi+4wKF3xrB+N1qXiZYoqDeaK5lNRAkNsHKmXeCPfg==

[email protected]:
version "0.4.11"
Expand Down Expand Up @@ -5175,7 +5175,7 @@ pkg-dir@^3.0.0:
version "0.0.1"
dependencies:
hyperscript-helpers "^3.0.3"
planetwars-match-log "file:../../../../../../../../home/wout/.cache/yarn/v4/npm-planetwars-visualizer-0.0.1-f88cf828-5292-4a7f-a080-f588fc7f9073-1550433915040/node_modules/match-log"
planetwars-match-log "file:../../../../../../../../home/wout/.cache/yarn/v4/npm-planetwars-visualizer-0.0.1-68fb02b6-97ba-451b-b0aa-151e8e462421-1550439613076/node_modules/match-log"
react-hyperscript "^3.2.0"

plist@^3.0.1:
Expand Down

0 comments on commit b1de2a7

Please sign in to comment.