1.3.1 • Published 12 months ago

node-red-contrib-logger-vh v1.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

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:

FieldVariableDefaultDetail
LogLevelsmsg.logLever or manual"debug"Four log levels are supported: debug, info, warning and error
Groupmsg.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).
Flowmsg.flow or manual/The name of the flow in which the log node is located (e.g. standard .env-variable NR_FLOW_NAME).
Keymsg.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 IDmsg.traceId or manual/A field to store a unique trace ID if required
Applicationmsg.application or manual"node-red instance"The name of the application.
servermsg.serveros.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.
Usermsg.user"node-red user"The name of the (service) account that runs the application.
ProcessIdprocess.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.

logger

Testing

The unit tests use the Mocha framework.

To run the tests, execute the following command:

$ npm run test
1.3.1

12 months ago

1.2.2

1 year ago

1.3.0

12 months ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago