Merge pull request #1117 from TomCassWindred/IndividualLogEnable

Individual log enable
This commit is contained in:
hydroflame 2021-08-31 16:22:34 -04:00 committed by GitHub
commit 0eeb868e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

@ -187,7 +187,7 @@ export class WorkerScript {
} }
shouldLog(fn: string): boolean { shouldLog(fn: string): boolean {
return (this.disableLogs.ALL == null && this.disableLogs[fn] == null); return (this.disableLogs[fn] == null);
} }
log(func: string, txt: string): void { log(func: string, txt: string): void {

@ -943,11 +943,17 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.clearLog(); workerScript.scriptRef.clearLog();
}, },
disableLog: function(fn) { disableLog: function(fn) {
if (possibleLogs[fn]===undefined) { if (fn = "ALL") {
throw makeRuntimeErrorMsg("disableLog", `Invalid argument: ${fn}.`); for (fn in possibleLogs) {
workerScript.disableLogs[fn] = true;
} }
workerScript.log("disableLog", `Disabled logging for all functions`);
} else if (possibleLogs[fn] === undefined) {
throw makeRuntimeErrorMsg("disableLog", `Invalid argument: ${fn}.`);
} else {
workerScript.disableLogs[fn] = true; workerScript.disableLogs[fn] = true;
workerScript.log("disableLog", `Disabled logging for ${fn}`); workerScript.log("disableLog", `Disabled logging for ${fn}`);
}
}, },
enableLog: function(fn) { enableLog: function(fn) {
if (possibleLogs[fn]===undefined) { if (possibleLogs[fn]===undefined) {
@ -4545,7 +4551,7 @@ function NetscriptFunctions(workerScript) {
return functionNames; return functionNames;
} }
const possibleLogs = Object.fromEntries(["ALL", ...getFunctionNames(functions)].map(a => [a, true])) const possibleLogs = Object.fromEntries([...getFunctionNames(functions)].map(a => [a, true]))
return functions; return functions;
} // End NetscriptFunction() } // End NetscriptFunction()