diff --git a/packages/node_modules/@node-red/nodes/core/common/lib/debug/debug-utils.js b/packages/node_modules/@node-red/nodes/core/common/lib/debug/debug-utils.js index c4931c285..3dba41654 100644 --- a/packages/node_modules/@node-red/nodes/core/common/lib/debug/debug-utils.js +++ b/packages/node_modules/@node-red/nodes/core/common/lib/debug/debug-utils.js @@ -392,12 +392,28 @@ RED.debug = (function() { if (o) { stack.push(o); } if (!busy && (stack.length > 0)) { busy = true; - processDebugMessage(stack.shift()); - setTimeout(function() { - busy = false; - handleDebugMessage(); - }, 15); // every 15mS = 66 times a second - if (stack.length > numMessages) { stack = stack.splice(-numMessages); } + const message = stack.shift() + // call any preDebugLog hooks, allowing them to modify the message or block it from being displayed + RED.hooks.trigger('debugPreProcessMessage', { message }).then(result => { + if (result === false) { + return false; // A hook returned false - halt processing of this message + } + return processDebugMessage(message); + }).then(processArtifacts => { + if (processArtifacts === false) { + return false; // A hook returned false - halt processing of this message + } + const { message, element, payload } = processArtifacts || {}; + return RED.hooks.trigger('debugPostProcessMessage', { message, element, payload }); + }).catch(err => { + console.error("Error in debug process message hooks", err); + }).finally(() => { + setTimeout(function() { + busy = false; + handleDebugMessage(); + }, 15); // every 15mS = 66 times a second + if (stack.length > numMessages) { stack = stack.splice(-numMessages); } + }) } } @@ -519,10 +535,13 @@ RED.debug = (function() { sourceId: sourceNode && sourceNode.id, rootPath: path, nodeSelector: config.messageSourceClick, - enablePinning: true + enablePinning: true, + tools: o.tools // permit preDebugLog hooks to add extra tools to the element }); // Do this in a separate step so the element functions aren't stripped debugMessage.appendTo(el); + // add the meta row tools container, even if there are no tools, so that the postProcessDebugMessage hook can add tools + const tools = $('').appendTo(metaRow) // NOTE: relying on function error to have a "type" that all other msgs don't if (o.hasOwnProperty("type") && (o.type === "function")) { var errorLvlType = 'error'; @@ -534,7 +553,6 @@ RED.debug = (function() { msg.addClass('red-ui-debug-msg-level-' + errorLvl); $('function : (' + errorLvlType + ')').appendTo(metaRow); } else { - var tools = $('').appendTo(metaRow); var filterMessage = $('').appendTo(tools); filterMessage.on("click", function(e) { e.preventDefault(); @@ -590,6 +608,14 @@ RED.debug = (function() { if (atBottom) { messageList.scrollTop(sbc.scrollHeight); } + + // return artifacts to permit postProcessDebugMessage hooks to modify the message element, access the + // processed payload or otherwise modify the message after it has been generated. + return { + message: o, // original debug message object, useful for any hook that might have tagged additional info onto it + element: msg, // the top-level element for this debug message + payload // the reconstructed debug message + } } function clearMessageList(clearFilter, filteredOnly) {