mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-12-11 20:15:30 +01:00
Updated log files with -client/-worker/-headless suffixes
This commit is contained in:
parent
f837b56898
commit
97f98f33d0
@ -22,6 +22,8 @@ export class AppContext {
|
||||
private _ui: UI;
|
||||
private _workerController: WorkerController;
|
||||
public constructor() {
|
||||
Logger.Get.enableLogToFile();
|
||||
Logger.Get.initLogFile('client');
|
||||
Logger.Get.enableLOG();
|
||||
Logger.Get.enableLOGMAJOR();
|
||||
Logger.Get.enableLOGWARN();
|
||||
@ -71,7 +73,7 @@ export class AppContext {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this._ui.enableTo(action + 1);
|
||||
this._ui.enable(action + 1);
|
||||
|
||||
const { builder, style } = this._getActionMessageBuilder(action, payload.statusMessages);
|
||||
uiOutput.setMessage(builder, style as OutputStyle);
|
||||
|
||||
@ -1,43 +1,59 @@
|
||||
import fs from 'fs';
|
||||
import { AppConfig } from '../config';
|
||||
import util from 'util';
|
||||
|
||||
import { AppConfig } from '../config';
|
||||
import { FileUtil } from './file_util';
|
||||
import { AppPaths, PathUtil } from './path_util';
|
||||
|
||||
/**
|
||||
* Performs console.log if logging LOG is enabled
|
||||
* Logs to console and file if logging `LOG` is enabled.
|
||||
* This should be used for verbose logs.
|
||||
* @see LOG_MAJOR
|
||||
*/
|
||||
export const LOG = (...data: any[]) => {
|
||||
if (Logger.Get.isLOGEnabled()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(...data);
|
||||
}
|
||||
Logger.Get.logToFile(...data);
|
||||
if (Logger.Get.logToFile) {
|
||||
Logger.Get.logToFile(...data);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs console.log if logging LOG_MAJOR is enabled
|
||||
* Logs to console and file if logging `LOG_MAJOR` is enabled.
|
||||
* This is identical to `LOG` but can be enabled/disabled separately.
|
||||
* This should be used for important logs.
|
||||
* @see LOG
|
||||
*/
|
||||
export const LOG_MAJOR = (...data: any[]) => {
|
||||
if (Logger.Get.isLOGMAJOREnabled()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(...data);
|
||||
}
|
||||
Logger.Get.logToFile(...data);
|
||||
if (Logger.Get.logToFile) {
|
||||
Logger.Get.logToFile(...data);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs console.warn if logging LOG_WARN is enabled
|
||||
* Logs a warning to the console and file if logging `LOG_WARN` is enabled.
|
||||
*/
|
||||
export const LOG_WARN = (...data: any[]) => {
|
||||
if (Logger.Get.isLOGWARNEnabled()) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(...data);
|
||||
}
|
||||
Logger.Get.logToFile(...data);
|
||||
if (Logger.Get.logToFile) {
|
||||
Logger.Get.logToFile(...data);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts a timer.
|
||||
* @see `TIME_END` To stop the timer.
|
||||
* @param label The ID of this timer.
|
||||
*/
|
||||
export const TIME_START = (label: string) => {
|
||||
if (Logger.Get.isLOGTIMEEnabled()) {
|
||||
// eslint-disable-next-line no-console
|
||||
@ -45,6 +61,11 @@ export const TIME_START = (label: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops a timer and prints the time elapsed. Not logged to file.
|
||||
* @see `TIME_START` To start the timer.
|
||||
* @param label The ID of this timer.
|
||||
*/
|
||||
export const TIME_END = (label: string) => {
|
||||
if (Logger.Get.isLOGTIMEEnabled()) {
|
||||
// eslint-disable-next-line no-console
|
||||
@ -52,9 +73,15 @@ export const TIME_END = (label: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs an error to the console and file, always.
|
||||
*/
|
||||
/* eslint-disable-next-line no-console */
|
||||
export const LOG_ERROR = console.error;
|
||||
|
||||
/**
|
||||
* Logger controls enable/disabling the logging functions above.
|
||||
*/
|
||||
export class Logger {
|
||||
/* Singleton */
|
||||
private static _instance: Logger;
|
||||
@ -67,6 +94,8 @@ export class Logger {
|
||||
private _enabledLOGWARN: boolean;
|
||||
private _enabledLOGTIME: boolean;
|
||||
|
||||
private _enabledLogToFile?: boolean;
|
||||
|
||||
private _logStream?: fs.WriteStream;
|
||||
|
||||
private constructor() {
|
||||
@ -74,62 +103,134 @@ export class Logger {
|
||||
this._enabledLOGMAJOR = false;
|
||||
this._enabledLOGWARN = false;
|
||||
this._enabledLOGTIME = false;
|
||||
}
|
||||
|
||||
FileUtil.mkdirSyncIfNotExist(AppPaths.Get.logs);
|
||||
if (AppConfig.LOG_TO_FILE) {
|
||||
this._logStream = fs.createWriteStream(PathUtil.join(AppPaths.Get.logs, `./${Date.now()}.log`));
|
||||
/**
|
||||
* Setup the log file.
|
||||
* @param suffix The suffix to append to the end of the log file name.
|
||||
*/
|
||||
public initLogFile(suffix: string) {
|
||||
if (this._logStream === undefined && this._enabledLogToFile === true) {
|
||||
FileUtil.mkdirSyncIfNotExist(AppPaths.Get.logs);
|
||||
this._logStream = fs.createWriteStream(PathUtil.join(AppPaths.Get.logs, `./${Date.now()}-${suffix}.log`));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs to the log file if setup.
|
||||
* @param data The data to print.
|
||||
*/
|
||||
public logToFile(...data: any[]) {
|
||||
this._logStream?.write(util.format(...data) + '\n');
|
||||
if (this._logStream && this._enabledLogToFile) {
|
||||
this._logStream.write(`${util.format(...data)}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow `LOG` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public enableLOG() {
|
||||
this._enabledLOG = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent `LOG` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public disableLOG() {
|
||||
this._enabledLOG = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow `LOG_MAJOR` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public enableLOGMAJOR() {
|
||||
this._enabledLOGMAJOR = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent `LOG_MAJOR` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public disableLOGMAJOR() {
|
||||
this._enabledLOGMAJOR = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow `LOG_WARN` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public enableLOGWARN() {
|
||||
this._enabledLOGWARN = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent `LOG_WARN` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public disableLOGWARN() {
|
||||
this._enabledLOGWARN = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow `TIME_START`/`TIME_END` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public enableLOGTIME() {
|
||||
this._enabledLOGTIME = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent `TIME_START`/`TIME_END` calls to be printed to the console and to the log file if setup.
|
||||
*/
|
||||
public disableLOGTIME() {
|
||||
this._enabledLOGTIME = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow console log calls to logged to the log file if setup.
|
||||
* Should be called before `initLogFile`
|
||||
*/
|
||||
public enableLogToFile() {
|
||||
if (AppConfig.LOG_TO_FILE && this._enabledLogToFile === undefined) {
|
||||
this._enabledLogToFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent console log calls to logged to the log file if setup.
|
||||
*/
|
||||
public disableLogToFile() {
|
||||
this._enabledLogToFile = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not `LOG` calls should be printed to the console and log file.
|
||||
*/
|
||||
public isLOGEnabled() {
|
||||
return this._enabledLOG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not `LOG_MAJOR` calls should be printed to the console and log file.
|
||||
*/
|
||||
public isLOGMAJOREnabled() {
|
||||
return this._enabledLOGMAJOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not `LOG_WARN` calls should be printed to the console and log file.
|
||||
*/
|
||||
public isLOGWARNEnabled() {
|
||||
return this._enabledLOGWARN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not `TIME_START`/`TIME_END` calls should be printed to the console and log file.
|
||||
*/
|
||||
public isLOGTIMEEnabled() {
|
||||
return this._enabledLOGTIME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not console log calls should be logged to the log file if setup.
|
||||
*/
|
||||
public isLogToFileEnabled() {
|
||||
return this.logToFile;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import { VoxelMesh } from './voxel_mesh';
|
||||
import { IVoxeliser } from './voxelisers/base-voxeliser';
|
||||
import { VoxeliserFactory } from './voxelisers/voxelisers';
|
||||
import { AssignParams, ExportParams, ImportParams, RenderBlockMeshParams, RenderMeshParams, RenderVoxelMeshParams, VoxeliseParams } from './worker_types';
|
||||
import { Logger } from './util/log_util';
|
||||
|
||||
export class WorkerClient {
|
||||
private static _instance: WorkerClient;
|
||||
@ -18,6 +19,8 @@ export class WorkerClient {
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
Logger.Get.enableLogToFile();
|
||||
Logger.Get.initLogFile('worker');
|
||||
}
|
||||
|
||||
private _loadedMesh?: Mesh;
|
||||
|
||||
@ -3,6 +3,7 @@ import { ColourSpace } from '../../src/util';
|
||||
import { AppPaths, PathUtil } from '../../src/util/path_util';
|
||||
import { runHeadless, THeadlessConfig } from '../../tools/headless';
|
||||
import { FileUtil } from '../../src/util/file_util';
|
||||
import { TEST_PREAMBLE } from '../preamble';
|
||||
|
||||
const baseConfig: THeadlessConfig = {
|
||||
import: {
|
||||
@ -35,6 +36,8 @@ const baseConfig: THeadlessConfig = {
|
||||
};
|
||||
|
||||
test('FULL Obj->Obj', () => {
|
||||
TEST_PREAMBLE();
|
||||
|
||||
AppPaths.Get.setBaseDir(PathUtil.join(__dirname, '../..'));
|
||||
FileUtil.mkdirSyncIfNotExist(PathUtil.join(AppPaths.Get.testData, '../out/'));
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { ColourSpace } from '../../src/util';
|
||||
import { AppPaths, PathUtil } from '../../src/util/path_util';
|
||||
import { runHeadless, THeadlessConfig } from '../../tools/headless';
|
||||
import { FileUtil } from '../../src/util/file_util';
|
||||
import { TEST_PREAMBLE } from '../preamble';
|
||||
|
||||
const baseConfig: THeadlessConfig = {
|
||||
import: {
|
||||
@ -35,6 +36,8 @@ const baseConfig: THeadlessConfig = {
|
||||
};
|
||||
|
||||
test('FULL Obj->Obj', () => {
|
||||
TEST_PREAMBLE();
|
||||
|
||||
AppPaths.Get.setBaseDir(PathUtil.join(__dirname, '../..'));
|
||||
FileUtil.mkdirSyncIfNotExist(PathUtil.join(AppPaths.Get.testData, '../out/'));
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { ColourSpace } from '../../src/util';
|
||||
import { AppPaths, PathUtil } from '../../src/util/path_util';
|
||||
import { runHeadless, THeadlessConfig } from '../../tools/headless';
|
||||
import { FileUtil } from '../../src/util/file_util';
|
||||
import { TEST_PREAMBLE } from '../preamble';
|
||||
|
||||
const baseConfig: THeadlessConfig = {
|
||||
import: {
|
||||
@ -35,6 +36,8 @@ const baseConfig: THeadlessConfig = {
|
||||
};
|
||||
|
||||
test('FULL Obj->Obj', () => {
|
||||
TEST_PREAMBLE();
|
||||
|
||||
AppPaths.Get.setBaseDir(PathUtil.join(__dirname, '../..'));
|
||||
FileUtil.mkdirSyncIfNotExist(PathUtil.join(AppPaths.Get.testData, '../out/'));
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import { ColourSpace } from '../../src/util';
|
||||
import { AppPaths, PathUtil } from '../../src/util/path_util';
|
||||
import { runHeadless, THeadlessConfig } from '../../tools/headless';
|
||||
import { FileUtil } from '../../src/util/file_util';
|
||||
import { TEST_PREAMBLE } from '../preamble';
|
||||
|
||||
const baseConfig: THeadlessConfig = {
|
||||
import: {
|
||||
@ -35,6 +36,8 @@ const baseConfig: THeadlessConfig = {
|
||||
};
|
||||
|
||||
test('FULL Obj->Schematic', () => {
|
||||
TEST_PREAMBLE();
|
||||
|
||||
AppPaths.Get.setBaseDir(PathUtil.join(__dirname, '../..'));
|
||||
FileUtil.mkdirSyncIfNotExist(PathUtil.join(AppPaths.Get.testData, '../out/'));
|
||||
|
||||
|
||||
5
tests/preamble.ts
Normal file
5
tests/preamble.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Logger } from "../src/util/log_util"
|
||||
|
||||
export const TEST_PREAMBLE = () => {
|
||||
Logger.Get.disableLogToFile();
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
import { LOG_MAJOR } from '../src/util/log_util';
|
||||
import { Logger, LOG_MAJOR } from '../src/util/log_util';
|
||||
import { AppPaths, PathUtil } from '../src/util/path_util';
|
||||
import { runHeadless } from './headless';
|
||||
import { headlessConfig } from './headless-config';
|
||||
|
||||
void async function main() {
|
||||
AppPaths.Get.setBaseDir(PathUtil.join(__dirname, '../..'));
|
||||
Logger.Get.enableLogToFile();
|
||||
Logger.Get.initLogFile('headless');
|
||||
|
||||
runHeadless(headlessConfig);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user