Writing general log to file

Hi,
I would like to enable nr to log to a file and to syslog.

I found in the net a post to do it this like in the settings.js:

     logging: {
         /** Only console logging is currently supported */
         console: {
             /** Level of logging to be recorded. Options are:
              * fatal - only those errors which make the application unusable should be recorded
              * error - record errors which are deemed fatal for a particular request + fatal errors
              * warn - record problems which are non fatal + errors + fatal errors
              * info - record information about the general running of the application + warn + error + fatal errors
              * debug - record information which is more verbose than info + info + warn + error + fatal errors
              * trace - record very detailed logging + debug + info + warn + error + fatal errors
              * off - turn off all logging (doesn't affect metrics or audit)
              */
             level: "info",
             /** Whether or not to include metric events in the log output */
             metrics: false,
             /** Whether or not to include audit events in the log output */
             audit: false
         },
         file: {
           level: "debug",
           audit: true,
           filename: "/var/log/nodered.log"
         }
     },

But it does not seem to work.
I would like to log login attempts to the file.

Is there any way to get this working. I am not realy able to write a customlogger.

Thanks
Karl-Heinz

Does the directory /var/log exist?

Whereabouts is this settings.js file? What directory is it in?

Did you restart node-red after changing this settings file?

And more importantly by default only root (and possibly the syslog group) can write to /var/log and you REALLY REALLY should not be running Node-RED as root without a VERY clear understanding of what you are doing.

Hi,

  1. /var/log is the standard directory of ubuntu to store logfiles. So it exists!
  2. the settings.js is in the directory .node-red of the user where node-red runs.
  3. yes, the user can write to the directory and the logfile. I checked it by "echo 'xxx'>>/var/log/nodered.log" from the user where nodered runs and I did not receive any errormessage. Naturally the text was in the logfile - I checked that.
  4. yes, I restarted nodered

Did you manually create the log file with the appropriate permissions or did it just work? node red should not be able to create a file there.

Did you add that whole section into settings.js or did you edit the existing settings for logging and just add the file: section?

Hang on, I'm 99.5% sure there is no built in logging to file in Node-RED, you need to write your own custom logging plugin using the API described here:

I have used node-red-contrib-flogger in the past and found it useful. It is old but still installs ok.

By default node-red will log to the system journal from debug nodes and methods such as node.warn() in function nodes. You can use journalctl to access the system journal.

  1. I manually created the file with the appropriate permissions and tested it as described.
  2. I only added the section with file: to the settings.js

If I am not wrong, this will log actions from some nodes inside node-red.
But I want to log all loggings to the file. Everything what currently will get logged to syslog.

But, I think, according to @hardillb, the post I read somewhere how to add the file:-section to the settings.js will not work at all since, if i understand @hardillb correct, node-red does only log to "console" or "customlogger".

So the post I followed from somewhere was pobably missleading.

How do you start Node-red running?

If it is a systemd service you can add this to the [service] section of nodered.service:

StandardOutput=append:/var/log/nrlogfile.log
StandardError=append:/var/log/nrlogfile.log

You probably want to arrange the logfiles to be included in standard log rotation (assuming Ubuntu does this). Some of the logging levels in settings.js result in a lot of output!

Are you running under systemd?

If so, by default (on Debian and derivations anyway), systemd has its own logging BUT the logs are sync'd to syslog as far as I remember. Oh, actually Debian ships with a tool that does the sync, other distro's might not do that by default.

Systemd journals (logs) write to /var/log/journal/..... The files are by source user:


The files are not text though.

As jbudd has said, you can also tell systemd to output to specific log files. However, I don't think those will then rotate and so you will need to do something to control the size. journald also keeps the files locked open so rotating them may be complex.

Similarly, if you roll your own logs using Node-RED's settings, you must also handle your own rotation/clear-down.

Best bet is to sync the journald logs to syslog.

Personally, I find that the only reason to roll your own Node-RED log is for some special purpose. For example, I have a special log function on my dev instance that outputs trace level outputs for uibuilder but info level for everything else. Also, I don't write that to file, I send each output to MQTT and I have a flow and uibuilder-driven web page to show the logs.