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

**URL:** <https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879>\
**Category:** General\
**Tags:** function-node, log\
**Created:** [24 January 2024 13:31 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879 "2024-01-24T13:31:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geheim](https://avatars.discourse-cdn.com/v4/letter/g/e8c25b/32.png) [@Geheim](https://discourse.nodered.org/u/Geheim)\
**Post date:** [24 January 2024 13:31 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879/1 "2024-01-24T13:31:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [24 January 2024 13:37 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879/2 "2024-01-24T13:37:12Z")

</div>

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](https://nodered.org/docs/user-guide/runtime/logging#metrics) 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](https://nodered.org/docs/api/hooks/messaging/)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [24 January 2024 13:40 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879/3 "2024-01-24T13:40:06Z")

</div>

> [@knolleary](#):
>
> 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](https://nodered.org/docs/api/hooks/messaging/)

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 January 2024 13:40 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879/4 "2024-01-24T13:40:42Z")

</div>

You tagged your question function-node.

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

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 January 2024 23:14 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879/5 "2024-01-24T23:14:00Z")

</div>

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

Craig

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 April 2024 23:14 UTC](https://discourse.nodered.org/t/how-can-we-log-some-data-with-node-name-at-the-start-of-each-node-and-at-the-end-of-each-node/84879/6 "2024-04-23T23:14:27Z")

</div>

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