Node Red Debug In System Console

Hey folks - what’s the best way to search for JSON msg objects from debug nodes that are output to the system console? I looked in the system log but couldn’t find anything.

image

Do you mean this?

image

Apparently, if Node-RED has been started from a command line, then this is the ‘system console’. However, if Node-RED has been started as a service (ie as HA addon) then there is no console and it may (or may not) go to the log file.

https://nodered.org/docs/user-guide/runtime/logging

https://nodered.org/docs/user-guide/writing-functions#logging-events

I work on the basis that output to the system console transmogrifies directly back into nano-bits and hides behind the skirting board.

Ahh ok bummer. Yeah so what I’m trying to achieve is getting debug output on long running things (e.g. time triggers) to see if they’re working properly. But the debug pane has to be open for it to get populated.

Is there a better way to achieve what I’m trying to get so I can look at debug info over the course of 24-48 hours?

For myself, I use Context.

I have set up persistent context which writes to ‘file’ so I can save over restarts and such, and I push stuff to context arrays for both working flows and debugging.

I like to use arrays, and it is not too difficult to push new records, and pop off old ones to effectively run a ring-buffer, which in context can be both viewed and extracted with ease.

The following bit of JS I use in a function node to capture an object (I track NR memory use)

let memMon = flow.get("Memory", "persist") || [];

if (memMon.length > 300) { memMon.pop() }

memMon.unshift({ "Time": msg.payload.time_number, "rss": msg.payload.rss, "heap": msg.payload.heap, "usedheap": msg.payload.used_heap })

flow.set("Memory", memMon, "persist");
msg.payload = memMon;
return msg;

The second parameter in the flow.get is the name of my persistent memory to differentiate from ‘default’.

The pop keeps the array length at 300
The unshift pushes, but at the front of the array (which makes life easier for me when reading it in context)

Thanks - how/where do you write to the file?

I don’t. To explain more fully, I use Node-RED context (usually the flow context) and store stuff there. So as to ensure that it remains over restarts and the like, I use persistent context, and have added this in the NR settings.

https://nodered.org/docs/user-guide/context#saving-context-data-to-the-file-system

If you modify the settings.js file for the Node-RED at the ‘context’ point to something like

    // The following property can be used to enable context storage. The configuration
    // provided here will enable file-based context that flushes to disk every 30 seconds.
    // Refer to the documentation for further options: https://nodered.org/docs/api/context/
    //
  contextStorage: {
    default: { module: "memory" },
    persist: { module: "localfilesystem" }
  },

then you will find you have two stores - the default is just to memory (so vanishes on NR restarts) but the ‘persist’ (call it what you like) gets flushed to file every 30 seconds. It is not always reboot-proof, but it provides an easy to use, easy to read, easy to work with on-board filing system.

The great thing about this is it can be read visually, it can be deleted easily, it can be written to and read from using just a change node. Plus, with a change node, you can write or read sub elements from complex objects.