npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

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.

logger

Testing

The unit tests use the Mocha framework.

To run the tests, execute the following command:

$ npm run test