Added logging with configurable levels to make debugging easier.

This commit is contained in:
n1474335 2017-12-28 18:17:38 +00:00
parent 124ff83206
commit d079420d46
17 changed files with 88 additions and 18 deletions

View file

@ -34,6 +34,7 @@ const Chef = function() {
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
*/
Chef.prototype.bake = async function(input, recipeConfig, options, progress, step) {
log.debug("Chef baking");
let startTime = new Date().getTime(),
recipe = new Recipe(recipeConfig),
containsFc = recipe.containsFlowControl(),
@ -69,7 +70,7 @@ Chef.prototype.bake = async function(input, recipeConfig, options, progress, ste
try {
progress = await recipe.execute(this.dish, progress);
} catch (err) {
console.log(err);
log.error(err);
error = {
displayStr: err.displayStr,
};
@ -112,6 +113,8 @@ Chef.prototype.bake = async function(input, recipeConfig, options, progress, ste
* @returns {number} The time it took to run the silent bake in milliseconds.
*/
Chef.prototype.silentBake = function(recipeConfig) {
log.debug("Running silent bake");
let startTime = new Date().getTime(),
recipe = new Recipe(recipeConfig),
dish = new Dish("", Dish.STRING);

View file

@ -42,6 +42,8 @@ self.postMessage({
self.addEventListener("message", function(e) {
// Handle message
const r = e.data;
log.debug("ChefWorker receiving command '" + r.action + "'");
switch (r.action) {
case "bake":
bake(r.data);
@ -61,6 +63,9 @@ self.addEventListener("message", function(e) {
r.data.pos
);
break;
case "setLogLevel":
log.setLevel(r.data, false);
break;
default:
break;
}
@ -121,7 +126,7 @@ function loadRequiredModules(recipeConfig) {
let module = self.OperationConfig[op.op].module;
if (!OpModules.hasOwnProperty(module)) {
console.log("Loading module " + module);
log.info("Loading module " + module);
self.sendStatusMessage("Loading module " + module);
self.importScripts(self.docURL + "/" + module + ".js");
}

View file

@ -111,6 +111,7 @@ Dish.enumLookup = function(typeEnum) {
* @param {number} type - The data type of value, see Dish enums.
*/
Dish.prototype.set = function(value, type) {
log.debug("Dish type: " + Dish.enumLookup(type));
this.value = value;
this.type = type;
@ -141,6 +142,8 @@ Dish.prototype.get = function(type) {
* @param {number} toType - The data type of value, see Dish enums.
*/
Dish.prototype.translate = function(toType) {
log.debug(`Translating Dish from ${Dish.enumLookup(this.type)} to ${Dish.enumLookup(toType)}`);
// Convert data to intermediate byteArray type
switch (this.type) {
case Dish.STRING:

View file

@ -150,14 +150,17 @@ Recipe.prototype.execute = async function(dish, startFrom) {
for (let i = startFrom; i < this.opList.length; i++) {
op = this.opList[i];
if (op.isDisabled()) {
log.debug(`[${i}] '${op.name}' is disabled`);
continue;
}
if (op.isBreakpoint()) {
log.debug(`[${i}] Pausing at breakpoint on '${op.name}'`);
return i;
}
try {
input = dish.get(op.inputType);
log.debug(`[${i}] Executing '${op.name}'`);
if (op.isFlowControl()) {
// Package up the current state