From 8fb1804571aec0f2346d141639cbf195034933d0 Mon Sep 17 00:00:00 2001 From: Lucas Dower Date: Fri, 16 Sep 2022 18:48:52 +0100 Subject: [PATCH] Disabled queueing actions for now, enabled file logs --- src/app_context.ts | 13 +++++++++---- src/config.ts | 2 +- src/ui/layout.ts | 6 ++++++ src/util/log_util.ts | 16 ++++++++-------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/app_context.ts b/src/app_context.ts index ca6a715..2640a39 100644 --- a/src/app_context.ts +++ b/src/app_context.ts @@ -14,7 +14,7 @@ import { UI } from './ui/layout'; import { UIMessageBuilder } from './ui/misc'; import { ColourSpace, EAction } from './util'; import { ASSERT } from './util/error_util'; -import { Logger } from './util/log_util'; +import { LOG_ERROR, Logger } from './util/log_util'; import { TWorkerJob, WorkerController } from './worker_controller'; import { TFromWorkerMessage, TToWorkerMessage } from './worker_types'; @@ -46,17 +46,18 @@ export class AppContext { public do(action: EAction) { this._ui.cacheValues(action); this._ui.disable(action); + this._ui.disableAll(); const workerJob = this._getWorkerJob(action); if (workerJob === undefined) { - this._ui.enable(action); + this._ui.enableTo(action); return; } const uiOutput = this._ui.getActionOutput(action); const jobCallback = (payload: TFromWorkerMessage) => { - this._ui.enable(action); + this._ui.enableTo(action); switch (payload.action) { case 'KnownError': case 'UnknownError': { @@ -66,10 +67,11 @@ export class AppContext { [payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'], 'error', ); + LOG_ERROR(payload.error); break; } default: { - this._ui.enable(action + 1); + this._ui.enableTo(action + 1); const { builder, style } = this._getActionMessageBuilder(action, payload.statusMessages); uiOutput.setMessage(builder, style as OutputStyle); @@ -171,6 +173,7 @@ export class AppContext { [payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'], 'error', ); + LOG_ERROR(payload.error); break; } default: { @@ -244,6 +247,7 @@ export class AppContext { [payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'], 'error', ); + LOG_ERROR(payload.error); break; } default: { @@ -315,6 +319,7 @@ export class AppContext { [payload.action === 'KnownError' ? payload.error.message : 'Something unexpectedly went wrong'], 'error', ); + LOG_ERROR(payload.error); break; } default: { diff --git a/src/config.ts b/src/config.ts index 492a1a6..f0988ad 100644 --- a/src/config.ts +++ b/src/config.ts @@ -35,5 +35,5 @@ export namespace AppConfig { export const MAXIMUM_IMAGE_MEM_ALLOC = 512; /** Whether of not all logs should be saved to a file */ - export const LOG_TO_FILE = false; + export const LOG_TO_FILE = true; } diff --git a/src/ui/layout.ts b/src/ui/layout.ts index 91d765e..e19d340 100644 --- a/src/ui/layout.ts +++ b/src/ui/layout.ts @@ -482,6 +482,12 @@ export class UI { return this._uiDull; } + public enableTo(action: EAction) { + for (let i = 0; i <= action; ++i) { + this.enable(i); + } + } + public enable(action: EAction) { if (action >= EAction.MAX) { return; diff --git a/src/util/log_util.ts b/src/util/log_util.ts index e5d71a9..e3ee627 100644 --- a/src/util/log_util.ts +++ b/src/util/log_util.ts @@ -12,8 +12,8 @@ export const LOG = (...data: any[]) => { if (Logger.Get.isLOGEnabled()) { // eslint-disable-next-line no-console console.log(...data); - Logger.Get.logToFile(...data); } + Logger.Get.logToFile(...data); }; /** @@ -23,8 +23,8 @@ export const LOG_MAJOR = (...data: any[]) => { if (Logger.Get.isLOGMAJOREnabled()) { // eslint-disable-next-line no-console console.log(...data); - Logger.Get.logToFile(...data); } + Logger.Get.logToFile(...data); }; /** @@ -34,8 +34,8 @@ export const LOG_WARN = (...data: any[]) => { if (Logger.Get.isLOGWARNEnabled()) { // eslint-disable-next-line no-console console.warn(...data); - Logger.Get.logToFile(...data); } + Logger.Get.logToFile(...data); }; /* eslint-disable no-console */ @@ -55,7 +55,7 @@ export class Logger { private _enabledLOGMAJOR: boolean; private _enabledLOGWARN: boolean; - private _logStream: fs.WriteStream; + private _logStream?: fs.WriteStream; private constructor() { this._enabledLOG = false; @@ -63,13 +63,13 @@ export class Logger { this._enabledLOGWARN = false; FileUtil.mkdirSyncIfNotExist(AppPaths.Get.logs); - this._logStream = fs.createWriteStream(PathUtil.join(AppPaths.Get.logs, `./${Date.now()}.log`)); + if (AppConfig.LOG_TO_FILE) { + this._logStream = fs.createWriteStream(PathUtil.join(AppPaths.Get.logs, `./${Date.now()}.log`)); + } } public logToFile(...data: any[]) { - if (AppConfig.LOG_TO_FILE) { - this._logStream.write(util.format(...data) + '\n'); - } + this._logStream?.write(util.format(...data) + '\n'); } public enableLOG() {