Add debug message pre and post hooks

pull/5495/head
Steve-Mcl 2026-02-23 11:25:59 +00:00
parent 8ceacdb565
commit 7ab239a50d
1 changed files with 34 additions and 8 deletions

View File

@ -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 <debugMessage> 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 = $('<span class="red-ui-debug-msg-tools button-group"></span>').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);
$('<span class="red-ui-debug-msg-topic">function : (' + errorLvlType + ')</span>').appendTo(metaRow);
} else {
var tools = $('<span class="red-ui-debug-msg-tools button-group"></span>').appendTo(metaRow);
var filterMessage = $('<button class="red-ui-button red-ui-button-small"><i class="fa fa-caret-down"></i></button>').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) {