bunyan-logdna-stream
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i bunyan-logdna-stream

Weekly Downloads

132

Version

1.1.0

License

MIT

Unpacked Size

9.48 kB

Total Files

9

Last publish

Collaborators

  • morlok