node-red-contrib-logger-vh
v1.3.1
Published
Node-RED node to log to the debug window, the console, a file or to the ELK stack
Downloads
22
Maintainers
Readme
node-red-contrib-logger-vh
A module for Node-RED that allows you to log to the following outputs:
- ELK stack (ElasticSearch & Logstash) via HTTP
- Files
- System Console
- Debug window
The winston
and winston-logging
libraries are used for this.
This project is based on node-red-contrib-advanced-logger and node-red-contrib-log-elk.
Installation
Run the following command in your Node-RED directory:
npm i node-red-contrib-logger-vh
This command can also be embedded in a Dockerfile, alongside any other NPM package installations.
Features
Four outputs are supported, which are all discussed below. The log message itself can be a string
a JSON
object or the entire msg
object. In each log message, several fields and meta data can be added next to the message to log itself:
| Field | Variable | Default | Detail |
| ----------- | --------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| LogLevels | msg.logLever
or manual | "debug" | Four log levels are supported: debug
, info
, warning
and error
|
| Group | msg.group
or manual | / | The name of the group in Node-RED in which the log node is located (e.g. standard .env
-variable from Node-RED: NR_GROUP_NAME
). |
| Flow | msg.flow
or manual | / | The name of the flow in which the log node is located (e.g. standard .env
-variable NR_FLOW_NAME
). |
| Key | msg.key
or manual | / | A free string field in which you can place specific information to link different messages to each other (e.g. "customerId: 123"). |
| Trace ID | msg.traceId
or manual | / | A field to store a unique trace ID if required |
| Application | msg.application
or manual | "node-red instance" | The name of the application. |
| server | msg.server
| os.hostname()
| The name of the server. By default, the name is retrieved by using os.hostname()
, but this will not work when running in Docker. |
| User | msg.user
| "node-red user" | The name of the (service) account that runs the application. |
| ProcessId | process.pid()
| / | The process ID is filled in automatically and can be helpful when many parallel processes are running. |
ELK Stack
You can log directly to Elastic. For this, you can:
- Define an arbitrary index name
- Set up the data to be sent as a data stream
- Log via Logstash
- Add username and password for basic authentication
Log via Logstash
If you choose to log to Logstash instead of logging to Elastic directly, you need to check the 'Logstash' option in the configuration node. The index name is appended to the URL, just as you would normally log to Elastic. You don't need to use this, but if requested, you can filter the index name from the URL in a Logstash pipeline. An example of a .conf
file could be:
input {
http {
port => 5000
codec => "json"
}
}
filter {
if ![url][path] or [url][path] == "/" {
mutate {
add_field => { "index" => "logs" }
}
} else {
grok {
match => { "[url][path]" => "/(?<index>.*)" }
}
}
}
output {
elasticsearch {
hosts => ["${ELASTIC_HOSTS}"]
user => "${ELASTIC_USER}"
password => "${ELASTIC_PASSWORD}"
index => "%{index}"
action => "create"
}
}
Here, the name of the index is taken from the URL or defaulted to 'logs'. For example:
POST http://logstash:5000/node-red-logs
This will log to the 'node-red-logs' index in Elastic. If not required, you can leave out the 'filter' section and just fill in the 'index' manually.
Files
- Choose file name
- Set maximum size
- Set maximum number of log files
Examples
See the examples
directory.
Testing
The unit tests use the Mocha framework.
To run the tests, execute the following command:
$ npm run test