How can we log some data with node name at the start of each node and at the end of each node?

I am developing a flow where I need to log the start and end event of each node with some custom information attached in the logs. For example,
Starting Log: Node named A type json has started its execution for data $msg.payload
Ending Log: Node named A type json has been executed for data $msg.payload

I tried using the complete node and a debug along with it but we do not get the source of node from where the control reaches to complete node in the msg.
I tried to use status node and then a function but not all nodes emit status event which gets caught on the node. I want to avoid explicitly altering all the common nodes.
Please suggest a way/existing library to perform the above task.

WHilst it doesn't give you exactly what you want, you can enable the metrics log level which will emit events around flow execution. It does not include message contents, but does include the node id.

See Logging : Node-RED for details.

An alternative would be to use the hooks api to add a custom handler in the message path that logs whatever you want: Messaging Hooks : Node-RED

1 Like

Just note @Geheim,
The messaging hooks are for custom developed nodes/plugins, it cant be used in a function node. (unless things have changed)

You tagged your question function-node.

In a function you can include
console.log("Node named A has started...")

Also look at the flogger node - lots of options in there for logging additional info.

Craig

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.