# Recommendations on how to do logging through function nodes

**URL:** <https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898>\
**Category:** General\
**Created:** [8 February 2023 16:26 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898 "2023-02-08T16:26:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brolaugh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brolaugh/32/71972_2.png) [@brolaugh](https://discourse.nodered.org/u/brolaugh)\
**Post date:** [8 February 2023 16:26 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/1 "2023-02-08T16:26:19Z")

</div>

I've read through the docs about logging here [Logging : Node-RED](https://nodered.org/docs/user-guide/runtime/logging) where it mentions that there's several log levels. However... I haven't found how I can actually log to these different levels in a function node. What I have observed however is that

`node.error()` produces error  
`node.log()` produces info

but where are the other log levels and how do I produce a log with that level?

Going through `console` there's no filtering whatsoever, I guess this is what nodered uses under the hood?

```auto
console.info()
console.error()
console.debug()
console.warn()
console.debug()
console.trace()

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 February 2023 19:56 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/2 "2023-02-08T19:56:54Z")

</div>

Did it occur to you that if `console` has those functions, maybe `node` does as well? 😉

If ever you want to discover what properties an object might have, this is good code to know:

```auto
msg.payload = Object.keys(node)
return msg

```

Add a debug node after that function node and you will see all of the properties.

---

<div class="post-metadata">

**Author:** ![brolaugh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brolaugh/32/71972_2.png) [@brolaugh](https://discourse.nodered.org/u/brolaugh)\
**Post date:** [10 February 2023 08:57 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/3 "2023-02-10T08:57:32Z")

</div>

That didn't occour to me at all 😅

---

<div class="post-metadata">

**Author:** ![brolaugh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brolaugh/32/71972_2.png) [@brolaugh](https://discourse.nodered.org/u/brolaugh)\
**Post date:** [10 February 2023 15:14 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/4 "2023-02-10T15:14:51Z")

</div>

With that said though it would probably be a good idea to explicitly state this in the documentation.  
Cause to me running `Object.keys(someObject)` on every framework related object doesn't feel like a good developer experience. I'd be happy to make PR for it but I can't find a documentation repo.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [10 February 2023 15:16 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/5 "2023-02-10T15:16:38Z")

</div>

It [has been documented](https://nodered.org/docs/user-guide/writing-functions#node).

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [10 February 2023 19:53 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/6 "2023-02-10T19:53:06Z")

</div>

> [@brolaugh](#):
>
> With that said though it would probably be a good idea to explicitly state this in the documentation.

I believe all of the relevant properties of the node object ARE documented. The `object.keys` trick is just that, a quick and dirty trick do dump the structure of an object.

> [@brolaugh](#):
>
> Cause to me running `Object.keys(someObject)` on every framework related object doesn't feel like a good developer experience.

Actually, it is a pretty decent developer experience for something quick and dirty when you don't want to hunt through the documentation 😁 I certainly wouldn't expect anyone to have to do that regularly.

In this case, the logging functions follow a very standard naming convention anyway. And they are indeed documented.

> [@brolaugh](#):
>
> I'd be happy to make PR for it but I can't find a documentation repo.

> **[GitHub - node-red/node-red.github.io: Node-RED Site](https://github.com/node-red/node-red.github.io)**
>
> Node-RED Site. Contribute to node-red/node-red.github.io development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![brolaugh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brolaugh/32/71972_2.png) [@brolaugh](https://discourse.nodered.org/u/brolaugh)\
**Post date:** [10 February 2023 20:23 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/7 "2023-02-10T20:23:07Z")

</div>

I had a hard time finding that section when googling as I could only find the [Logging : Node-RED](https://nodered.org/docs/user-guide/runtime/logging) page. Suggested a change in the docs so hopefully no one else does the same mistake.  
[[Docs] Add link to logging API in logging section by brolaugh · Pull Request #307 · node-red/node-red.github.io · GitHub](https://github.com/node-red/node-red.github.io/pull/307)

---

<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:** [11 April 2023 20:23 UTC](https://discourse.nodered.org/t/recommendations-on-how-to-do-logging-through-function-nodes/74898/8 "2023-04-11T20:23:53Z")

</div>

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