From b1de2a777e9a6599667b2c428d80dc958cdad635 Mon Sep 17 00:00:00 2001 From: Wout Schellaert Date: Sun, 17 Feb 2019 22:59:32 +0100 Subject: [PATCH] Update electron-log and fix renderer logging --- planetwars/client/app/main_process.ts | 10 +++--- planetwars/client/app/process/index.ts | 7 ++++ .../app/{ => process}/main/app_listeners.ts | 0 .../app/{ => process}/main/extensions.ts | 0 .../client/app/{ => process}/main/index.ts | 1 - .../client/app/{ => process}/main/menu.ts | 0 .../client/app/{ => process}/main/window.ts | 0 planetwars/client/app/process/shared/index.ts | 1 + .../app/{main => process/shared}/logging.ts | 34 +++++++++++-------- planetwars/client/app/render_process.tsx | 8 ++++- planetwars/client/package.json | 2 +- planetwars/client/yarn.lock | 10 +++--- 12 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 planetwars/client/app/process/index.ts rename planetwars/client/app/{ => process}/main/app_listeners.ts (100%) rename planetwars/client/app/{ => process}/main/extensions.ts (100%) rename planetwars/client/app/{ => process}/main/index.ts (80%) rename planetwars/client/app/{ => process}/main/menu.ts (100%) rename planetwars/client/app/{ => process}/main/window.ts (100%) create mode 100644 planetwars/client/app/process/shared/index.ts rename planetwars/client/app/{main => process/shared}/logging.ts (54%) diff --git a/planetwars/client/app/main_process.ts b/planetwars/client/app/main_process.ts index 60a1f65d..8dc85d95 100644 --- a/planetwars/client/app/main_process.ts +++ b/planetwars/client/app/main_process.ts @@ -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 @@ -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); diff --git a/planetwars/client/app/process/index.ts b/planetwars/client/app/process/index.ts new file mode 100644 index 00000000..7b94cf7a --- /dev/null +++ b/planetwars/client/app/process/index.ts @@ -0,0 +1,7 @@ +import * as main from './main'; +import * as shared from './shared'; + +export { + main, + shared, +}; diff --git a/planetwars/client/app/main/app_listeners.ts b/planetwars/client/app/process/main/app_listeners.ts similarity index 100% rename from planetwars/client/app/main/app_listeners.ts rename to planetwars/client/app/process/main/app_listeners.ts diff --git a/planetwars/client/app/main/extensions.ts b/planetwars/client/app/process/main/extensions.ts similarity index 100% rename from planetwars/client/app/main/extensions.ts rename to planetwars/client/app/process/main/extensions.ts diff --git a/planetwars/client/app/main/index.ts b/planetwars/client/app/process/main/index.ts similarity index 80% rename from planetwars/client/app/main/index.ts rename to planetwars/client/app/process/main/index.ts index 4cf38b53..915eb78f 100644 --- a/planetwars/client/app/main/index.ts +++ b/planetwars/client/app/process/main/index.ts @@ -1,4 +1,3 @@ -export * from './logging'; export * from './app_listeners'; export * from './window'; export * from './menu'; diff --git a/planetwars/client/app/main/menu.ts b/planetwars/client/app/process/main/menu.ts similarity index 100% rename from planetwars/client/app/main/menu.ts rename to planetwars/client/app/process/main/menu.ts diff --git a/planetwars/client/app/main/window.ts b/planetwars/client/app/process/main/window.ts similarity index 100% rename from planetwars/client/app/main/window.ts rename to planetwars/client/app/process/main/window.ts diff --git a/planetwars/client/app/process/shared/index.ts b/planetwars/client/app/process/shared/index.ts new file mode 100644 index 00000000..6658f8bb --- /dev/null +++ b/planetwars/client/app/process/shared/index.ts @@ -0,0 +1 @@ +export * from './logging'; \ No newline at end of file diff --git a/planetwars/client/app/main/logging.ts b/planetwars/client/app/process/shared/logging.ts similarity index 54% rename from planetwars/client/app/main/logging.ts rename to planetwars/client/app/process/shared/logging.ts index c8d89d8e..3384b3b0 100644 --- a/planetwars/client/app/main/logging.ts +++ b/planetwars/client/app/process/shared/logging.ts @@ -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"); @@ -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; } } diff --git a/planetwars/client/app/render_process.tsx b/planetwars/client/app/render_process.tsx index f7d7d149..06bf174c 100644 --- a/planetwars/client/app/render_process.tsx +++ b/planetwars/client/app/render_process.tsx @@ -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'; @@ -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 diff --git a/planetwars/client/package.json b/planetwars/client/package.json index fd9d9bfc..f31841e5 100644 --- a/planetwars/client/package.json +++ b/planetwars/client/package.json @@ -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", diff --git a/planetwars/client/yarn.lock b/planetwars/client/yarn.lock index 481e3828..b1394a0f 100644 --- a/planetwars/client/yarn.lock +++ b/planetwars/client/yarn.lock @@ -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== electron-osx-sign@0.4.11: version "0.4.11" @@ -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: