log4js-logstash

0.2.3 • Public • Published

log4js-logstash

Build Status

This is a very simple log4js appender that can talk to logstash instances. This version is still very specific to Gembly Games B.V. but feel free to fork and adjust =)

Installation

You can install install log4js-logstash by adding this .git url to your package.json

Usage: logstash configuration

In the "input" part of the logstash server conf :

input {
	tcp {
		codec => "json"
		data_timeout => 10
		port => 5959
		type => "tcp-input"
	}
}

Usage: log4js configuration

Plain javascript

    var log4js = require('log4js');
    log4js.configure({
        "appenders": [
            {
                "category": "TEST",
                "type": "log4js-logstash",
                "host": "localhost",
                "port": 5959,
                "fields": {
                    "instance": "MyAwsInstance",
                    "source": "myApp",
                    "environment": "development"
                }
            },
            {
                "category": "tests",
                "type": "console"
            }
        ],
        "levels": {
            "tests":  "DEBUG"
        }
    });
 
    var log = log4js.getLogger('tests');
 
    log.error('hello hello');

Or in YAML

appenders:
  [
    {
        type: 'console',
        category:
          [
            'WEBSERVER','TEST'
          ]
    },
    {
        type: 'log4js-logstash',
        host: 'localhost',
        port: 5959,
        batch: {
            size: 200,
            timeout: 10
        },
        fields: {
            instance: 'MyAwsInstance',
            source: 'myApp',
            environment: 'development',
        },
        category:
          [
            'WEBSERVER','TEST'
          ]
    }
  ]
replaceConsole: true

Package Sidebar

Install

npm i log4js-logstash

Weekly Downloads

258

Version

0.2.3

License

none

Last publish

Collaborators

  • alebles