Node-RED supports console logging and custom logging modules.
Console logging
To use console log, you can set the following configuration in settings.js.
// Configure the logging output
logging: {
// Console logging
console: {
level: "info",
metrics: false,
audit: false
}
}
There are 3 configurations, (level, metrics and audit) available in the settings.js file.
level
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 - no log messages at all
metrics
When you set metrics: true
, the Node-RED runtime outputs flow execution and memory usage.
Flow execution
Received and sent events in each node are output into the log. For example, the following logs are output from the flow which has inject and debug nodes.
9 Mar 13:57:53 - [metric] {"level":99,"nodeid":"8bd04b10.813f58","event":"node.inject.receive","msgid":"86c8212c.4ef45","timestamp":1489067873391}
9 Mar 13:57:53 - [metric] {"level":99,"nodeid":"8bd04b10.813f58","event":"node.inject.send","msgid":"86c8212c.4ef45","timestamp":1489067873392}
9 Mar 13:57:53 - [metric] {"level":99,"nodeid":"4146d01.5707f3","event":"node.debug.receive","msgid":"86c8212c.4ef45","timestamp":1489067873393}
Memory usage
Node-RED monitors memory usage every 15 seconds.
9 Mar 13:56:24 - [metric] {"level":99,"event":"runtime.memory.rss","value":97517568,"timestamp":1489067784815}
9 Mar 13:56:24 - [metric] {"level":99,"event":"runtime.memory.heapTotal","value":81846272,"timestamp":1489067784817}
9 Mar 13:56:24 - [metric] {"level":99,"event":"runtime.memory.heapUsed","value":59267432,"timestamp":1489067784817}
audit
When you set audit: true
, the Admin HTTP API access events are logged with end point, IP address and time stamp.
Open Node-RED editor
9 Mar 13:49:42 - [audit] {"event":"library.get.all","type":"flow","level":98,"path":"/library/flows","ip":"127.0.0.1","timestamp":1489067382686}
9 Mar 13:49:42 - [audit] {"event":"nodes.list.get","level":98,"path":"/nodes","ip":"127.0.0.1","timestamp":1489067382786}
9 Mar 13:49:42 - [audit] {"event":"nodes.configs.get","level":98,"path":"/nodes","ip":"127.0.0.1","timestamp":1489067382861}
9 Mar 13:49:43 - [audit] {"event":"flows.get","version":"v2","level":98,"path":"/flows","ip":"127.0.0.1","timestamp":1489067383051}
9 Mar 13:49:43 - [audit] {"event":"comms.open","level":98,"timestamp":1489067383080}
Hit deploy button
9 Mar 13:47:14 - [audit] {"event":"flows.set","type":"full","version":"v2","level":98,"path":"/flows","ip":"127.0.0.1","timestamp":1489067234101}
Close Node-RED editor
9 Mar 13:49:42 - [audit] {"event":"comms.close","level":98,"timestamp":1489067382316}
Login and hit deploy button
If settings.js has access control configuration, Node-RED outputs the login users and their permission.
9 Mar 14:24:06 - [audit] {"event":"auth.login","username":"admin","client":"node-red-editor","scope":"*","level":98,"timestamp":1489069446376}
9 Mar 14:34:22 - [audit] {"event":"flows.set","type":"full","version":"v2","level":98,"user":{"username":"admin","permissions":"*"},"path":"/flows","ip":"127.0.0.1","timestamp":1489070062519}
Custom logging module
Node-RED also supports custom logging modules to output logs to other handlers.
Use case
- To output logs to log system outside of Node-RED
- To gather information from specific nodes
Configuration
To use a custom logger, edit settings.js
to add a new block in the logging section.
// Configure the logging output
logging: {
// Console logging
console: {
level: "info",
metrics: false,
audit: false
},
// Custom logger
custom: {
level: 'debug',
metrics: true,
handler: function(settings) {
return function(msg) {
console.log(msg.timestamp, msg.event);
}
}
}
}
The configurations of level and metrics are same as console logging. The handler should define the custom logging handler. You can use any name for the logging module except "console".