# How to setup log

**URL:** <https://discourse.nodered.org/t/how-to-setup-log/48069>\
**Category:** Dashboard\
**Created:** [6 July 2021 05:18 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069 "2021-07-06T05:18:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![WeeSeong](https://avatars.discourse-cdn.com/v4/letter/w/e19b73/32.png) [@WeeSeong](https://discourse.nodered.org/u/WeeSeong)\
**Post date:** [6 July 2021 05:18 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/1 "2021-07-06T05:18:48Z")

</div>

Hi everyone, is there a way to setup a log to monitor past data from an input? I'm still rather confused on how to set one after reading through some forums.

What I have in mind was to set the log to store up to 10 data or to display top 10 latest information for people to read.

Thanks in advance

---

<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:** [6 July 2021 20:34 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/2 "2021-07-06T20:34:27Z")

</div>

Do you want that data logged in Node-RED or in the browser? Both are possible.

---

<div class="post-metadata">

**Author:** ![WeeSeong](https://avatars.discourse-cdn.com/v4/letter/w/e19b73/32.png) [@WeeSeong](https://discourse.nodered.org/u/WeeSeong)\
**Post date:** [7 July 2021 01:17 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/3 "2021-07-07T01:17:54Z")

</div>

Ehhh I wanted to log the past few things registered through Node-RED and have the history of it displayed on the dashboard. Although, I've found a way to work on it, but the ui doesn't seem nice since I'm using the ui\_table to display the log. Any other suggestion on which node should I use?

---

<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:** [7 July 2021 02:00 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/4 "2021-07-07T02:00:19Z")

</div>

Here is a scrolling message table on the dashboard as well as writing to a log file on disk

One of the other members on here gave me the basic code for this a LONG time ago (sorry can't remember who) - i have not looked at it in more than a year or so - but should do what you want

```auto
[{"id":"75fcc40f.e3167c","type":"debug","z":"10b98a0a.175376","name":"Raw MQTT from the Pump Relay","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":480,"y":760,"wires":[]},{"id":"e965bc13.3213a","type":"mqtt in","z":"10b98a0a.175376","name":"Incoming MQTT from Tank Pump","topic":"stat/Tank_Top_Up_Pump/POWER","qos":"2","datatype":"auto","broker":"ee495ae9.36c048","x":190,"y":680,"wires":[["75fcc40f.e3167c","12741692.106189"]]},{"id":"7e84a9c8.9bf858","type":"function","z":"10b98a0a.175376","name":"Build Message for LogFile","func":"var topic = msg.topic;\nif (msg.payload === \"ON\") {\n var p = \"On\";\n } \nelse if (msg.payload === \"OFF\") { \n var p = \"Off\";\n }\nelse var p = \"Unknown\";\n\nvar d = flow.get(\"MyDateTime\") || \"0\";\n//var myCount = flow.get(\"count\", storeName);\n\n//create message to write to the log file\nvar payload1 = (d + \" Tank Pump is \" + p + \" Topic is: \" + msg.topic);\n//Store message so it can be output on output 1\nvar msg1 = { payload:payload1 };\n\n//Create 2nd message for screen writing on scrolling table\nvar payload2 = (d + \" Tank Pump is \" + p);\n//Store message so it can be output on output 2\nvar msg2 = { payload:payload2 };\n\nif (p == \"On\") {\nvar msg3 = { payload:'<i class=\"fa fa-refresh fa-spin fa-3x fa-fw\"></i>' };\n}\n\nif (p == \"Off\") {\nvar msg3 = { payload:'<i class=\"fa fa-stop-circle-o fa-3x fa-fw\"></i>' };\n}\n\n//End Function and return two messages on two outputs\nreturn [msg1, msg2, msg3,];\n\n","outputs":3,"noerr":0,"x":490,"y":680,"wires":[["f7fbd013.0037b","96d8b63f.b83e08"],["7c1b9286.bb8fdc"],["df59820b.7cf47"]]},{"id":"f7fbd013.0037b","type":"debug","z":"10b98a0a.175376","name":"Message for Logfile","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":790,"y":640,"wires":[]},{"id":"96d8b63f.b83e08","type":"file","z":"10b98a0a.175376","name":"Log info to the file","filename":"/home/pi/logs/Tank_Pump_Run_Stats","appendNewline":true,"createDir":true,"overwriteFile":"false","x":790,"y":680,"wires":[[]]},{"id":"65ccc534.c0a94c","type":"ui_template","z":"10b98a0a.175376","group":"c4fb7801.2972a8","name":"Water Tank Pump Status","order":0,"width":"10","height":"5","format":"<style>\n\n #tex1 {\n font-weight:bolder;\n font-size: 12;\n letter-spacing: 4px;\n fill: white;\n }\n \n</style>\n\n\n<svg height=\"300\" width=\"400\" >\n\n<text id=\"tex1\" x=\"10\" y=\"30\" > {{msg.payload[0]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"50\" > {{msg.payload[1]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"70\" > {{msg.payload[2]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"90\" > {{msg.payload[3]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"110\" > {{msg.payload[4]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"130\" > {{msg.payload[5]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"150\" > {{msg.payload[6]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"170\" > {{msg.payload[7]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"190\" > {{msg.payload[8]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"210\" > {{msg.payload[9]}} </text>\n</svg>\n\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":1070,"y":720,"wires":[[]]},{"id":"7c1b9286.bb8fdc","type":"function","z":"10b98a0a.175376","name":"Add word to scrolling table","func":"let pay = msg.payload;\n\n// Read scrolling table from context\nlet sctab = flow.get(\"sctab\");\n\n// Modify scrolling table by adding msg.payload as first element\nlet size = sctab.unshift(pay);\n\n// Remove last element from scrolling table\nif (size >9) sctab.pop();\n\n// Update context for scrolling text\nflow.set(\"sctab\",sctab);\n\n// Shalow copy updated scrolling table to msg.payload\nmsg.payload = [...sctab];\n\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":720,"wires":[["65ccc534.c0a94c"]]},{"id":"df59820b.7cf47","type":"ui_text","z":"10b98a0a.175376","group":"c4fb7801.2972a8","order":1,"width":"1","height":"1","name":"Water Tank Pump Running Status","label":"","format":"{{msg.payload}}","layout":"row-center","x":840,"y":780,"wires":[]},{"id":"12741692.106189","type":"rbe","z":"10b98a0a.175376","name":"Filter out Minute Status updates from Tasmota","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":520,"y":620,"wires":[["7e84a9c8.9bf858"]]},{"id":"ee495ae9.36c048","type":"mqtt-broker","z":"","name":"New-HA-Live","broker":"172.16.100.31","port":"1883","clientid":"Live-VM","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c4fb7801.2972a8","type":"ui_group","z":"","name":"Status Messages","tab":"7ded32a1.cf8ccc","order":2,"disp":true,"width":"10","collapse":false},{"id":"7ded32a1.cf8ccc","type":"ui_tab","z":"","name":"Water Tank","icon":"","order":2}]

```

Craig

---

<div class="post-metadata">

**Author:** ![WeeSeong](https://avatars.discourse-cdn.com/v4/letter/w/e19b73/32.png) [@WeeSeong](https://discourse.nodered.org/u/WeeSeong)\
**Post date:** [7 July 2021 04:28 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/5 "2021-07-07T04:28:53Z")

</div>

Hi Craig, is there a reason why the text's white?

---

<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:** [7 July 2021 04:30 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/6 "2021-07-07T04:30:09Z")

</div>

Nope not at all - probably because i use the dark theme?

Craig

---

<div class="post-metadata">

**Author:** ![WeeSeong](https://avatars.discourse-cdn.com/v4/letter/w/e19b73/32.png) [@WeeSeong](https://discourse.nodered.org/u/WeeSeong)\
**Post date:** [7 July 2021 06:26 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/7 "2021-07-07T06:26:37Z")

</div>

Ah, makes sense. Think that solved my issue on making the log, thank you so much!!

---

<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:** [7 July 2021 06:27 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/8 "2021-07-07T06:27:51Z")

</div>

No worries - i note there are a couple of trivial errors thrown in the Function node in the javascript code - you could probably clean it up and get rid of them with a little bit of playing.

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:** [21 July 2021 06:28 UTC](https://discourse.nodered.org/t/how-to-setup-log/48069/9 "2021-07-21T06:28:05Z")

</div>

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