Recommendations for logging / debugging

2,403 views
Skip to first unread message

Giles Roadnight

unread,
Jun 10, 2016, 11:22:21 AM6/10/16
to Node-RED
Hi All

Currently I have a whole load of commented out console.log lines in my node javascript. When my node stops working it's annoying having to un-commentthem all to see what's going wrong.

What's the recommended way of handling this?

I think I saw some nodes that had a second output for debug messages but this seems a bit obtuse to the user.

Nicholas O'Leary

unread,
Jun 10, 2016, 11:36:20 AM6/10/16
to Node-RED Mailing List
Giles,

we have multiple levels of logging in Node-RED, including 'debug' and 'trace' levels. Currently the Node object only exposes log/warn/error - all of which are intended for end-user consumption. To use debug/trace, you can use:

    RED.log.trace("my trace message");
    RED.log.debug("my debug message");  (unrelated to the 'Debug' messages you can generate in a flow)

By default, the logger used by Node-RED is set to only show Info or higher. If you want to capture these lower levels you'll need to tell the default logger to include them. In your settings file you should find a section called 'logging', and under that a log handler called 'console' - change it's 'level' value to 'trace' or 'debug' and you'll start seeing the messages in the console.

It is possible to add a custom log handler in there if you wanted to spool the trace/debug to a file and not fill the console with it. I don't think we have that documented - out of time right now, but will share an example later tonight.

I should add that currently we have absolutely nothing that makes use of the trace or debug levels ourselves. On my todo list for post-0.14 is to add some into the core to aid debugging certainly common scenarios (such as tracing the node-scanning path so you can see exactly where node-red is looking for nodes).

Nick



 

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Giles Roadnight

unread,
Jun 10, 2016, 11:49:12 AM6/10/16
to Node-RED Mailing List
OK, thanks. Don't worry about the custom log handler bit, I won't be writing one of them.

ajaykas...@gmail.com

unread,
Mar 20, 2017, 8:52:19 PM3/20/17
to Node-RED
Hi Nick,

I am on much older version of node-red, and the version is Node-RED version: v0.11.0, Node.js  version: v0.10.46. since we are currently using a device that can only support that particular version of nodejs.

Anyway getting to my question, can I not use RED.log.debug and RED.log.trace in the function nodes? As I am getting a Reference error as mentioned below "ReferenceError: RED is not defined (line 9, col 9)",  when using those calls? If I can't use the RED object in the function nodes, how do I achieve the equivalent of debug/trace level logging from within a function node?

Thanks,
Ajay.

Julian Knight

unread,
Mar 21, 2017, 4:09:47 PM3/21/17
to Node-RED
Are you writing your own node or are you using the function node in the admin interface?

For the first, this has the answer: https://nodered.org/docs/creating-nodes/node-js

For the second, you can just create a second output and pass a message to it then add a debug node to that output. Or you can use node.warn inside the function code.

Nick O'Leary

unread,
Mar 21, 2017, 5:39:39 PM3/21/17
to Node-RED Mailing List
Hi,

you mention the Function node; RED.log is not available in there. The docs explain how to do logging from a Function : http://nodered.org/docs/writing-functions#logging-events - although I can't remember if all of those features were available back in version 0.11. As a last resort, console.log should be available.

Nick

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

cin...@gmail.com

unread,
Mar 21, 2017, 6:13:32 PM3/21/17
to Node-RED
do you have any recommendations/rule of thumb how verbose the logging should be? For example connections/disconnections to a service...

ajaykas...@gmail.com

unread,
Mar 21, 2017, 10:52:06 PM3/21/17
to Node-RED
Thanks Julian for your suggestion. All I am trying to do is log from the function node. I do use the node.log or node.warn or node.error. However there are scenarios where I want to be able to use RED.log.debug or RED.log.Trace, where I want to actually write the data I am receiving or sending that would help me troubleshoot better., by increasing the logging level in a production scenario. 

However today morning I did find a hacky way to use the RED object, by referencing it in the globalContext section in settings.js and then I was able to get it to work. But not sure the node-red team would approve using the RED object in such a fashion from within the function node.

Thanks,
Ajay

Julian Knight

unread,
Mar 22, 2017, 4:36:56 AM3/22/17
to Node-RED
If I want that, I tend to simply dump the data to a second output. Then I can consume as JSON or reformat as desired. You could easily write that to a file or maybe MongoDB or CouchDB or indeed MQTT which I also use for recording debugging info which I then view in MQTT Spy which has a formatter for JSON that the author added at my request.

ajaykas...@gmail.com

unread,
Mar 23, 2017, 12:25:44 PM3/23/17
to Node-RED
Thanks I didn't think of the second o/p and routing my detailed logs via that o/p and potentially to a file system on the device. However was wondering what your thoughts are regarding logging via the RED object for more detailed logging, the way I am currently using it? Is there any potential performance impacts and/or disruptions that could occur in the node-red flows using the RED object directly from the function nodes?

Thanks,
Ajay

Julian Knight

unread,
Mar 23, 2017, 1:17:10 PM3/23/17
to Node-RED
No problem, there are usually 100 different ways to do these things :)

As for overheads of using RED, I can't think that there would be as it is already in memory. However, it would need Dave or Nick to identify potential pitfalls.

I might imagine that it could be pretty easy to destroy your NR instance but other than that! 

ajaykas...@gmail.com

unread,
Mar 23, 2017, 2:08:26 PM3/23/17
to Node-RED
Thanks Julian for your inputs. I am considering the second o/p option as I can pipe the detailed logs to a sub flow and process it separately in the flow and write it out to a destination that works best for us. This would also mean every function node that I have I will have  minimum two o/p's or more depending if I had already two on a function node.  One of the questions I meant to ask earlier, any changes I make to the settings.js file like if I want to increase log levels say, does that require an NR restart?

Thanks,
Ajay.

Nick O'Leary

unread,
Mar 23, 2017, 3:01:31 PM3/23/17
to Node-RED Mailing List
One of the questions I meant to ask earlier, any changes I make to the settings.js file like if I want to increase log levels say, does that require an NR restart?

Yes - settings.js is only loaded at startup - so a restart is needed to pickup any changes.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

ajaykas...@gmail.com

unread,
Mar 23, 2017, 5:20:47 PM3/23/17
to Node-RED
Thanks Nick, for the information. 


On Thursday, March 23, 2017 at 12:01:31 PM UTC-7, Nick O'Leary wrote:
One of the questions I meant to ask earlier, any changes I make to the settings.js file like if I want to increase log levels say, does that require an NR restart?

Yes - settings.js is only loaded at startup - so a restart is needed to pickup any changes.

Nick
On 23 March 2017 at 18:08, <ajaykas...@gmail.com> wrote:
Thanks Julian for your inputs. I am considering the second o/p option as I can pipe the detailed logs to a sub flow and process it separately in the flow and write it out to a destination that works best for us. This would also mean every function node that I have I will have  minimum two o/p's or more depending if I had already two on a function node.  One of the questions I meant to ask earlier, any changes I make to the settings.js file like if I want to increase log levels say, does that require an NR restart?

Thanks,
Ajay.

On Thursday, March 23, 2017 at 10:17:10 AM UTC-7, Julian Knight wrote:
No problem, there are usually 100 different ways to do these things :)

As for overheads of using RED, I can't think that there would be as it is already in memory. However, it would need Dave or Nick to identify potential pitfalls.

I might imagine that it could be pretty easy to destroy your NR instance but other than that! 

On Thursday, 23 March 2017 16:25:44 UTC, ajaykas...@gmail.com wrote:
Thanks I didn't think of the second o/p and routing my detailed logs via that o/p and potentially to a file system on the device. However was wondering what your thoughts are regarding logging via the RED object for more detailed logging, the way I am currently using it? Is there any potential performance impacts and/or disruptions that could occur in the node-red flows using the RED object directly from the function nodes?

Thanks,
Ajay

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
Reply all
Reply to author
Forward
0 new messages