JSPM

parseable-bunyan

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q34723F
  • License MIT

Parseable Bunyan raw stream

Package Exports

  • parseable-bunyan
  • parseable-bunyan/dist/cjs/packages/bunyan/src/index.js
  • parseable-bunyan/dist/es6/packages/bunyan/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parseable-bunyan) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Parseable-Bunyan

Parseable buffered stream plugin for the popular Node-Bunyan logging framework.

Dependencies

Installation

npm install parseable-bunyan
yarn add parseable-bunyan

Usage

Package is cjs and es6 compatible.

Logs are buffered in memory and flushed periodically for more efficient ingestion. By default a maxEntries of 250, and flushInterval of 5 seconds are used.

const { ParseableBunyan } = require('parseable-bunyan')
const bunyan = require('bunyan')

const parseableStream = new ParseableBunyan({
  url: process.env.PARSEABLE_URL, // Ex: 'https://parsable.myserver.local/api/v1/logstream'
  username: process.env.PARSEABLE_USERNAME,
  password: process.env.PARSEABLE_PASSWORD,
  logstream: process.env.PARSEABLE_LOGSTREAM, // The logstream name
  tags: { tag1: 'tagValue' } // optional tags to be added with each ingestion
  disableTLSCerts: true, // Optional: Default to false. Set to true to ignore invalid certificate
  http2: true, // Optional: Default to true. Set to false to use HTTP/1.1 instead of HTTP/2.0
  buffer: { maxEntries: 100, flushInterval: 5000 }, // Optional: Tune the default buffering options
  onError: error => console.error(error), // Optional: handle an error by yourself
  onRecord: record => { // optional onRecord event
    // Examples of what could be done here: exclude routes, methods, IPs and UAs
    const excludeMethods = 'HEAD,OPTIONS'
    const excludeRoutes = '/check'
    const EXCLUDEIPS = '192.168.1.1,192.168.1.2'
    const excludeUAs = 'UptimeRobot,AnnoyingUA'

    if (record.req) {
      if (excludeRoutes.includes(record.req.path)) {
        return false
      }
      if (excludeMethods.includes(record.req.method)) {
        return false
      }
      if (record.remoteAddress) {
        if (excludeIPs.some(ip => record.remoteAddress.includes(ip))) {
          return false
        }
      }            
      if (record.req.headers['user-agent']) {
        const _ua = record.req.headers['user-agent'].toLowerCase()
        if (excludeUAs.some(ua => _ua.includes(ua.toLowerCase()))) {
          return false
        }
      }
    }

    // You can also apply custom serialization here and return the serialized record.
  }
})

const bunyanLogger = bunyan.createLogger({
    name: 'logger',
    serializers, // optionally set your own serializers
    streams: [parseableStream]
  })

LICENCE

MIT