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:

image

When I use for example this simple test flow:

image

[{"id":"23df382c.058f38","type":"interval-length","z":"dc82a538.a81ba8","format":"mills","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"msecs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":false,"startup":false,"msgField":"customfield","timestampField":"timestamp","repeatTimeout":false,"name":"","x":840,"y":840,"wires":[["2cf9022f.d3f66e"],[]]},{"id":"be32c12.fd5c84","type":"inject","z":"dc82a538.a81ba8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":640,"y":840,"wires":[["23df382c.058f38"]]},{"id":"2cf9022f.d3f66e","type":"debug","z":"dc82a538.a81ba8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":840,"wires":[]}]

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

image

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:

image

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

Thanks !!!
Bart

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