Console and debug nodes output redirection to file or

#1

Is it possible to redirect (or preferably duplicate) console and debug nodes output to a file or something else like a DB or anything ... ?

It means that any console.log(), node.log(), node.warn(), node.error() command should also be redirected/duplicated ...

0 Likes

#2

you can add your own custom logger - https://nodered.org/docs/user-guide/logging

0 Likes

#3

Or, if you just want it written to a file, depending on how you run node-red, you can just redirect it's console output to a file.

2 Likes

#4

ok thanks to you both, this is a good starting point ... Sorry I completely overlooked that part of the docs ... :love_you_gesture:

0 Likes

#5

knolleary,

as i am trying to learn how to redirect console output to a file, i have discovered lots of responses that are similar to yours: "redirect the console output to a file."

but, i haven't found a good reference that shows how to do that. i found one that suggested it is an edit to my node-red.service, but when i made that change that i thought was recommended, the node-red service would not start.

do you happen to have a reference or code snippet that shows how to redirect the console output to a file for node-red running on ubuntu.

thanks in advance.

0 Likes

#6

If you're running it as a service, then the console output will already be captured in /var/log/system.log - along with the log output from other services.

You can get a filtered view by using the node-red-log command - or, if you don't have that command, then you can use sudo journalctl -f -u nodered -o cat.

0 Likes

#7

excellent. i am running Splunk Enterprise, so i will add /var/log/system.log as a monitored source.

i have been reading this morning about the logging section in settings.js and will likely do something there. but for now, this will get me what i need.

thank you for the quick response.

0 Likes

#8

knolleary,

here is an example of a reference that says " For example, to redirect stdout to myapp.log , start the daemon with:" and gives this: " $ nohup node myapp.js > myapp.log"

but it doesn't say where to put the redirect. it is in my node-red.service? my settings.js?

know what I mean, vern!

0 Likes

#9

As we use systemd for running it as a service then you may want to read this - https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file

But the easy way may be as Nick said - sudo journalctl -f -u nodered -o cat or maybe redirect that to a file sudo journalctl -f -u nodered -o cat > myfile.log

But if what you are really trying to do is log to splunk then it would probably be best to add a custom logger within settings.js to send the logs there directly.

0 Likes

#10

Here is what I am currently using (Debian, Linux):

daemon --name=node-red --pidfile=/var/run/user.progs/node-red.pid /usr/local/bin/node-red

This logs to syslog as node-red. I filter on this with rsyslogd. I think I created the user.progs directory with looser permission (1777) so that the user can write the PID file.

0 Likes