Coder Social home page Coder Social logo

bunyan-logdna-stream's Introduction

bunyan-logdna-stream

Build Status Coverage Status npm version

Write log to LogDNA by using Bunyan with optional context and message formatting.

Install

$ npm install bunyan-logdna-stream --save

Usage

const logdna = require('logdna')
const bunyan = require('bunyan')
const bunyanLogdna = require('bunyan-logdna-stream')

// create logdna client
const client = logdna.createLogger(KEY, OPTIONS)
const stream = new bunyanLogdna.LogDnaStream(client)

// create bunyan logger
const logger = bunyan.createLogger({
  name: 'logger',
  streams: [{
    level: 'debug',
    type: 'raw',
    stream: stream
  }]
})

When you creating LogDnaStream you can pass options to customize message.

// setup your stream
const stream = new bunyanLogdna.LogDnaStream(client, {
    formatMessage: (message, record) {
        return `${message} (type=${record.type})`
    }
})

// log message
logger.child({type: 'server'}).debug('server is running')

// logdna message: "server is running (type=server)"

Or customize context (additional log data shown in logdna after expand log message). By default all your extra data will be in context including hostname and pid.

// setup your stream
const stream = new bunyanLogdna.LogDnaStream(client, {
    formatContext: (context, record) {
        context.user = 'user123'
    }
})

// context:
{
    "hostname": "...",
    "pid": 1234,
    "user": "user123" // extra context info
}

Contributing

When submitting your pull-request try to follow those guides:

Licence

MIT © Dusan Kmet

bunyan-logdna-stream's People

Contributors

dkmorlok avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

00mjk

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.