Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@log4js-node/logstashudp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@log4js-node/logstashudp

Logstash UDP Appender for log4js-node

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Log4JS - Logstash UDP appender

This is an optional appender for log4js-node.

npm install @log4js-node/logstashudp

The logstashUDP appender supports sending log events to a Logstash server. It uses the node.js core UDP support, and so requires no extra dependencies. Remember to call log4js.shutdown in your application if you want the UDP socket closed cleanly.

Configuration

  • type - @log4js-node/logstashudp
  • host - string - hostname (or IP-address) of the logstash server
  • port - integer - port of the logstash server
  • layout - (optional, defaults to dummyLayout) - used for the message field of the logstash data (see layouts)
  • extraDataProvider - function (optional, defaults to put the second param of log to fields) - used to enhance the object sent to Logstash via UDP. this will be passed the log event and should return a object.

Example

default config

log4js.configure({
  appenders: {
    logstash: {
      type: '@log4js-node/logstashudp',
      host: 'log.server',
      port: 12345
    }
  },
  categories: {
    default: { appenders: ['logstash'], level: 'info' }
  }
});
const logger = log4js.getLogger();
logger.info("important log message", { cheese: 'gouda', biscuits: 'hobnob' });

This will result in a JSON message being sent to log.server:12345 over UDP, with the following format:

{
  '@version': '1',
  '@timestamp': '2014-04-22T23:03:14.111Z',
  'host': 'yourHostname',
  'level': 'INFO',
  'category': 'default',
  'message': 'important log message',
  'fields': {
    'biscuits': 'hobnob',
    'cheese': 'gouda'
  }
}

use estraDataProvider

log4js.configure({
  appenders: {
    logstash: {
      type: '@log4js-node/logstashudp',
      host: 'log.server',
      port: 12345,
      extraDataProvider: loggingEvent => ({
        host: 'anotherHostname',  // this will replace the default real host
        clientIp: '1.2.3.4', // this will be added
        fields: {
          tag: 'myTag', // this will be added to the fields
          pid: loggingEvent.pid, // this will be added to the fields
          cheese: 'defaultCheese' // this will be added to the fields but will not be replaced in this example
        }
      })
    }
  },
  categories: {
    default: { appenders: ['logstash'], level: 'info' }
  }
});
const logger = log4js.getLogger();
logger.info("important log message", { cheese: 'gouda', biscuits: 'hobnob' });

This will result in a JSON message being sent to log.server:12345 over UDP, with the following format:

{
  '@version': '1',
  '@timestamp': '2014-04-22T23:03:14.111Z',
  'host': 'anotherHostname',
  'level': 'INFO',
  'category': 'default',
  'message': 'important log message',
  'clientIp': '1.2.3.4',
  'fields': {
    'cheese': 'defaultCheese',
    'tag': 'myTag',
    'pid': 123
  }
}

So, if not using the default extraDataProvider, you have to put the second param of the log to the fields yourself if you want.

Keywords

FAQs

Package last updated on 30 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc