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.
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.
/var/log is the standard directory of ubuntu to store logfiles. So it exists!
the settings.js is in the directory .node-red of the user where node-red runs.
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.
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.
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.
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!
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:
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.