Coder Social home page Coder Social logo

bunyan-elasticsearch's Introduction

bunyan-elasticsearch

A Bunyan stream for saving logs into Elasticsearch.

Install

npm install bunyan-elasticsearch

Logstash Template

By default Logstash will create a dynamic template that will take care of crating .raw fields for your data. In order to replicate this behavior you will need to create the dynamic template manually. You will need to download template.json and run the following command from the same directory as that file:

curl -XPUT localhost:9200/_template/logstash -d @template.json

Example

var bunyan = require('bunyan');
var Elasticsearch = require('bunyan-elasticsearch');
var esStream = new Elasticsearch({
  indexPattern: '[logstash-]YYYY.MM.DD',
  type: 'logs',
  host: 'localhost:9200'
});
esStream.on('error', function (err) {
  console.log('Elasticsearch Stream Error:', err.stack);
});

var logger = bunyan.createLogger({
  name: "My Application",
  streams: [
    { stream: process.stdout },
    { stream: esStream }
  ],
  serializers: bunyan.stdSerializers
});

logger.info('Starting application on port %d', app.get('port'));

Options

  • client: Elasticsearch client. Defaults to new client created with current set of options as an argument
  • type {string|function}: Elasticsearch type field. Default: 'logs'
  • indexPattern {string}: Used to generate index if index option not set. Default: '[logstash-]YYYY.MM.DD'
  • index {string|function}: Elasticsearch index. Defaults to index generated using index pattern

Options type and index can be either a string or function. For these options, when the option is set to a function, the function is passed the log entry object as an argument

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.