Troubleshooting a custom node using logging

Hi folks,

I got a question about my node-red-contrib-interval-length node, which measures the time interval between consecutive input messages. In the config screen you can specify in which output message field that measurement needs to be stored. For example I want the measurement to be stored in msg.customfield:


When I use for example this simple test flow:



This works fine for me (i.e. the timeinterval is stored in msg.customfield):


However the user responded that this field doesn't show in his output message...
I have no clue what is going on there, since there is very little code involved. So I have created an "extra_logging" branch in my Github repository which he could install like this:

npm install bartbutenaers/node-red-contrib-interval-length#extra_logging

In this branch I have added some extra logging code:

console.log("************* START EXTRA LOGGING *************");
console.log("outputValue = " + outputValue);
console.log("node.msgField = " + node.msgField);
// Normally the interval value will be put in the msg,payload (overwriting the original input msg.payload value).
// But the user can explicitly require to put the interval value in another message field.
try {
   console.log("Now we will set the message property");
   RED.util.setMessageProperty(msg, node.msgField, outputValue, true);
   console.log("Now we have set the message property");
   console.log("msg[" + node.msgField + "] = " + msg[node.msgField]);
} catch(err) {
   console.log("Something went wrong: " + err.message);
   node.error("Error setting interval value in msg." + node.msgField + " : " + err.message);
console.log("************* STOP EXTRA LOGGING *************");

In my test setups I now see nicely some extra log lines:


But the user doesn't see this extra logging.
Does anybody have any tips of how I can troubleshoot this issue?

Thanks !!!

as usual - which versions of node.js and Node-RED are they running ? - on what platform ? are they running default install or embedded, docker etc. If you have a custom branch then add some debug at node load time also (ie at head of the .js file) so you know it has loaded ok.

1 Like

i'm running node-red on my pi ,i'm not at home right now but i managed to find a workaround for that problem:
i used a change node right before the interval node and moved msg.payload to something else in my case msg.val :wink:
It might just be a problem with my pi to be honest missing some dependencies or something it's such an easy fix i don't really care to investigate further,the node saved me a lot of time thank you Bart

1 Like