# \[Announce\] node-red-log-io

**URL:** <https://discourse.nodered.org/t/announce-node-red-log-io/94733>\
**Category:** Share Your Nodes\
**Tags:** debugging, log, debug\
**Created:** [19 January 2025 14:40 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733 "2025-01-19T14:40:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [19 January 2025 14:40 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/1 "2025-01-19T14:40:54Z")

</div>

logIO 1.0.0 is released.

> **[@zigasebenik/node-red-log-io](https://flows.nodered.org/node/@zigasebenik/node-red-log-io)**
>
> A Node-RED node to log input and output messages to various outputs.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [21 January 2025 08:40 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/2 "2025-01-21T08:40:49Z")

</div>

FYI I have created a separate subject for questions/comments and thanks !!

> [@Node-red-log-io - Questions and comments](https://discourse.nodered.org/t/node-red-log-io-questions-and-comments/94754):
>
> First, thank you for [node-red-log-io (node) - Node-RED](https://flows.nodered.org/node/@zigasebenik/node-red-log-io) it looks really promising. Being, so far, a rather heavy user of flogger I am giving it a go. It doesn't seem to be possible to set dynamically the log file name with a msg. Have I missed something ? I log messages out of mqtt in nodes. I need to split the logging using part of the topic (slightly more subtle than that, but, in short this is what I need). At the moment, it seems that I can't. If the logIO node is active and then greying …

Not sure what is the right practice, adding it here or creating a new topic.

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 09:09 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/3 "2025-01-21T09:09:43Z")

</div>

Hi @greengolfer  
I'll look into both things.

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 10:29 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/4 "2025-01-21T10:29:58Z")

</div>

Issue with button should be fixed in deployed version 1.0.1.

Regarding the dynamic filenames - how many different files are we talking here for your case, 10, 100, 1000?

Sadly this is not supported by winston library I'm using although that doesn't mean it's not possible. I'd had to create a new instance of logger for each dynamic filename but I'm a bit concerned about potential memory leaks if we're talking about hundreds of different files.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [20 January 2025 07:48 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/5 "2025-01-20T07:48:43Z")

</div>

First, thank you for [node-red-log-io (node) - Node-RED](https://flows.nodered.org/node/@zigasebenik/node-red-log-io) it looks really promising.  
Being, so far, a rather heavy user of flogger I am giving it a go.

It doesn't seem to be possible to set dynamically the log file name with a msg. Have I missed something ?  
I log messages out of mqtt in nodes. I need to split the logging using part of the topic (slightly more subtle than that, but, in short this is what I need). At the moment, it seems that I can't.

If the _logIO_ node is active and then greying the components button, it looks like one must deploy the node for the log to stop, unlike the usual debug.

Then, if I want to re-enable logging, it looks like I need to deploy in full for the change to be effective. Only deploying the changed node (here _logIO_) is not enough.

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 10:31 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/6 "2025-01-21T10:31:36Z")

</div>

@greengolfer thanks for letting me know.  
Let's continue debate here: [[Announce] node-red-log-io](https://discourse.nodered.org/t/announce-node-red-log-io/94733)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 January 2025 10:33 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/7 "2025-01-21T10:33:43Z")

</div>

I merged the post to keep things tidy.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [21 January 2025 11:53 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/8 "2025-01-21T11:53:29Z")

</div>

——  
Regarding the dynamic filenames - how many different files are we talking here for your case, 10, 100, 1000?  
——

In the range of 10. Not much.  
Thanks

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 14:48 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/9 "2025-01-21T14:48:17Z")

</div>

@greengolfer what you requested was added in version 1.1.0 and sample flow was added to examples.

### Specify fileName

**Bellow applies if output is set to `File`.**

By default, logIO will log messages to file name specified in logger properties. But you can also define file name dynamically through incoming message.

To do so, incoming message should have a _\_logIO_\_ object with key `fileName` set to the name of desired file.

```JSON
{
  "payload" : "your payload",
  "topic": "your topic",
  "_logIO_" : { "fileName": "logIO-%DATE%.error", logLevel: "error" }
}

```

### Specify dirName

**Bellow applies if output is set to `File`.**

By default, logIO will log messages to directory specified in logger properties. But you can also define directory dynamically through incoming message.

To do so, incoming message should have a _\_logIO_\_ object with key `dirName` set to the directory name.

```JSON
{
  "payload" : "your payload",
  "topic": "your topic",
  "_logIO_" : { "dirName": "/var/log/node-red/errors", "fileName": "logIO-%DATE%.error", logLevel: "error" }
}

```

**I should also add additional warning in case logging to files:**

> Have in mind that if you delete of manually save the file that logIO is writing logs to, it might not be recreated. Watcher observing the file changes in not 100% reliable, thus avoid modifying/deleting files that are currently in use by logIO.  
> If you delete the active log file and it's not automatically recreated, you'll have to redeploy the flow.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [21 January 2025 15:40 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/10 "2025-01-21T15:40:27Z")

</div>

Just tried 1.1.1. Great stuff for the filename ! Works perfectly.

There is still something not quite right in the on/off using the component button.

Here is what I can see:

- import example and deploy. Most of the case I am using "Modified nodes" deployment option.
- Inject, log perfectly
- tick the component to turn off logging. Status is changed.
- Inject, no log. What is expected
- deploy using **modified nodes**
- Inject, no log. What is expected
- tick the component to turn on logging.
- Deploy using **modified nodes** (important !!) Status is changed.
- Inject, no log. _NOT_ what should happen.

For the last three actions, If I do the exact same sequence but use **Full** to deploy then:

- tick the component to turn on logging.
- Deploy using **Full** , Status is changed.
- Inject, see log. What is expected.

So, the behaviour is different when deploying Full or Modified Nodes.

Thanks !!

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 15:44 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/11 "2025-01-21T15:44:26Z")

</div>

Can you share an example of your flow please. What exactly you mean by **modified nodes**?  
I'll definitely take a look, just trying to understand for easier reproduction.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [21 January 2025 15:47 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/12 "2025-01-21T15:47:27Z")

</div>

I am using the example flow:

 ![Screenshot 2025-01-21 at 16.45.31](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b4e4c379348423a798b9fb5239ee5735d8b62d4.png)

The "Modified Nodes" is the bottom option of the Deploy button:

 ![Screenshot 2025-01-21 at 16.46.07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5ebd9c356fffc5ee675dd2ccc42c5a45ccbb3916.png)

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 15:50 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/13 "2025-01-21T15:50:40Z")

</div>

Thanks. Was not aware of this one 🙂  
I'll take a look and deploy a fix when ready.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [21 January 2025 17:25 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/14 "2025-01-21T17:25:30Z")

</div>

Something else 😉

I am using the dynamic filename option/

If I set msg._logIO_ to :

```auto
{
    "fileName": gb & ".json",
    "dirName": "/log",
    "logLevel": "info"
}

```

using jsonata, msg.gb is a string.  
There is no DATE defined in the filename.

I can see that the DATE, in the format defined in the setup node of the log, is added at the end of the filename.

So the effective filename becomes: mystring.json.20250121

It is no really an issue, but, it is unexpected.  
So, I changed to :

```auto
{
    "fileName": gb & "-%DATE%.json",
    "dirName": "/log",
    "logLevel": "info"
}

```

I get mystring-2025-01-21.json  
Like that the json extension is kept.

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 18:49 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/15 "2025-01-21T18:49:29Z")

</div>

Please check the button behavior along with deploy of modified nodes only (version 1.1.2).

Should be fixed and now also status on the node should reflect the change immediately and not only upon save (to indicate if logging is active or paused).

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [21 January 2025 18:54 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/16 "2025-01-21T18:54:01Z")

</div>

I'll check tomorrow about %DATE% replacement. This is added by 3rd party lib so I'll have to check if something can be done.

I'll check and do one of these things:

- if `%DATE%` placeholder is omitted in file name, it should not be appended to the end of the file
- if that will not be possible, document this behavior.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [21 January 2025 20:26 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/17 "2025-01-21T20:26:55Z")

</div>

Works perfectly !  
Really great tool.

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [22 January 2025 09:51 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/18 "2025-01-22T09:51:21Z")

</div>

> [@ziga](#):
>
> - if `%DATE%` placeholder is omitted in file name, it should not be appended to the end of the file

Fixed in version 1.1.3. If `%DATE%` is missing in your filename, default date format won't be appended to the end of it.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 January 2025 10:33 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/19 "2025-01-22T10:33:17Z")

</div>

Hi, this looks promising. Particulaly interested in inline debug and file logging rolloed into one.

i just tried it out and it crashed my instance...

```auto
22 Jan 10:26:15 - [error] [function:Store Functions] TypeError: Cannot read properties of undefined (reading 'timestampFormat')
22 Jan 10:26:15 - [info] Started flows
Shelly gen1 server is listening on port 20001
2025-01-22 10:26:15.938 FATAL Logger Unhandled error detected: EACCES: permission denied, open '../logIO-2025-01-22.log'
22 Jan 10:26:15 - [red] Uncaught Exception:
22 Jan 10:26:15 - [error] Error: EACCES: permission denied, open '../logIO-2025-01-22.log'

```

I fully appreciate this could be down to settings I entered but an important point of node-red nodes is that you should handle all errors and not permit it to crash node-red.

Also note, this has caused node-red to bootloop (must be trying to do whatever it is doing on instantiation) - i had to restart in `--safe` mode.

  

This is the flow I created. It is running on Node-RED 4.0.8, Node v18, on a RPi. Hopefully it will help you debug and handle the error?

```auto
[{"id":"447eae4d60cc3635","type":"logIO","z":"90e2df527c725ffb","name":"logIO 1","active":true,"logger":"41c90633a0d14285","complete":"payload","targetType":"msg","logIOMode":"wired","logIOScope":"IO","autoStart":true,"scope":[],"x":560,"y":620,"wires":[]},{"id":"adab22809f7213b2","type":"inject","z":"90e2df527c725ffb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":620,"wires":[["447eae4d60cc3635"]]},{"id":"41c90633a0d14285","type":"logIO-logger","name":"file-debug","logLevel":"debug","isTimestampUTC":false,"logMeta":"all","logMetaOptions":"","logOutput":"file,nr-debugger","fileFileName":"logIO-%DATE%.log","fileDirName":"../","fileDatePattern":"YYYY-MM-DD","fileIsJsonFormat":false,"fileZippedArchive":false,"fileMaxSize":"1","fileMaxSizeUnit":"m","fileMaxFiles":"3","fileMaxFilesUnit":"","consoleIsJsonFormat":false,"elkUrl":"http://localhost:9200","elkIndex":"node-red"}]

```

---

<div class="post-metadata">

**Author:** ![ziga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ziga/32/98138_2.png) [@ziga](https://discourse.nodered.org/u/ziga)\
**Post date:** [22 January 2025 10:37 UTC](https://discourse.nodered.org/t/announce-node-red-log-io/94733/20 "2025-01-22T10:37:17Z")

</div>

Will check yes, tnx for the logs.

[Next page](https://discourse.nodered.org/t/announce-node-red-log-io/94733.md?page=2)
