es-logger

0.3.0 • Public • Published

node-es-logger v0.3.0

This module creates a bunyan logger instance with an output stream bound to elasticsearch instance with logstash compatible JSON format.

Options

  • name (required): Bunyan log name
  • host: Elasticsearch host. Defaults to localhost:9200
  • type: String or function, Elasticsearch type for log entry to be stored under
  • client: Elasticsearch client. See elasticsearch-js for more details. Useful when custom client options are needed, like setting the Elasticsearch client log level. When used, host is ignored
  • indexPattern: Pattern used to generate index name. See momentjs for more details. Defaults to [logstash-]YYYY.MM.DD
  • index: String or function, Elasticsearch index to store log entry under. When used, indexPattern is ignored
  • serializers: Array of objects, bunyan serializers. See node-bunyan for more details. Defaults to standard serializers
  • quiet: Boolean, whether to add the stdout stream to the logger

Minimal Example

var logger = require('es-logger').create({
 
    name: 'myapp'
 
});
 
logger.info({value: 123}, 'message');

This prints a JSON and also send it to elasticsearch instance at localhost:9200.

Example with type from function

var logger = require('es-logger').create({
 
    name: 'myapp',
    host: 'elasticsearch:9200',
    type: function (entry) {
        return entry['type'];
    }
});
 
logger.info({type: "request", method: "GET"});

Use with bonsai.io.

var logger = require('es-logger').create({
 
    name: 'myapp',
    host: 'username:password@myapp-name-123456789.us-west-2.bonsai.io'
 
});
 
logger.info({value: 123}, 'message');

This prints a JSON and also send it to bonsai's elasticsearch instance at myapp-name-123456789.us-west-2.bonsai.io.

see bunyan's README for what interfaces the logger has.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.0
    1
  • 0.2.1
    0
  • 0.2.0
    0
  • 0.1.1
    0

Package Sidebar

Install

npm i es-logger

Weekly Downloads

1

Version

0.3.0

License

MIT

Last publish

Collaborators

  • kt3k