Logging node wanted

#1

Hi, node-red newbie is here.

There is logging settings in .node-red/settings.js. The configuration of its 3 properties is clear. An ability of adding of custom logger is clear.

I wonder if the built-in logging saves any log-file? If yes, where? If no, is there something to enable/configure to log events at info-level?

0 Likes

#2

The default logging just writes to the standard output stream of the node process. Where that ends up will depend on how you are running node-red and where that redirects the standard output to.

0 Likes

#3

OK. Normally I run the node-red from shell as:

node-red-start

When it stops printing and the frontend appears in browser I press Ctrl+C in shell. Then the node-red works in background. Where the stdout is printed to and how to keep/redirect it?
Can this be good enough to keep the stdout in nohup.out:

nohup node-red-start &
0 Likes

#4

If you are running on a Raspberry Pi, you should find you have the command node-red-log available. This can be used to view the log.

Under the covers, Node-RED is being run as system process, logging to /var/log/system.log along with other processes. The node-red-log command provides a filtered view of just the Node-RED log output.

1 Like

#5

Indeed, I forgot to mention the node-red is running on RasPi.
node-red-log is useful for current debug: it is showing few last events and prints new events. Thank you. Good for debug.
However, it’s blocking shell and not full log.

I have added in my RasPi following command under an alias which shows one line per event of full log and non-blocking. Maybe useful for someone :slight_smile:

 grep "Node-RED" /var/log/syslog | sed "s/^.*Node-RED\[[0-9]*\]: //g" | paste -d ' ' - -

I think the topic is SOLVED:
Wire required events or node output into debug node. That’s enough for logging. And 2 useful ways to see the log exist.

0 Likes

#6

If you look at the node-red-log command all it is doing is
sudo journalctl -f -n 25 -u nodered -o cat
which bascially prints the last 25 lines and then tails the log for more… you can instead just
sudo journalctl -u nodered -o cat
which will just print all the existing node-red entires in the log
(other parameters / options are available :slight_smile:

1 Like

#7

Use of journalcrl seems to be pretty effective. However, I like to see 1 event per line.
So I wrote tiny script, called it nrl (brief from node-red-log) and placed it into /usr/local/bin/.
Upload of the script doesn’t work here (only pictures allowed). So sharing it as text.

#!/usr/bin/python
''' Node-RED log parser.

    Authors: igrowing

'''

import re
import os

DATE_PTN = '(?sm)\w+ \w+ \d+:\d+:\d+.+?(?=\w+ \w+ \d+:\d+:\d+|}$)'

log = os.popen('grep "Node-RED" /var/log/syslog | sed "s/^.*Node-RED\[[0-9]*\]: //g"').read()
recs = re.findall(DATE_PTN, log)
for rec in recs:
    rec = rec.replace('\n', ' ')
    print rec + '}' if '{' in rec else rec
0 Likes

#8

Actually, there is a fair bit you can do to format the output. See: https://www.freedesktop.org/software/systemd/man/journalctl.html

Maybe add -o short or -o short-full to the command, that should get to single line entries.

0 Likes