bunyan-opbeat
Bunyan stream for Opbeat
Install
$ npm i --save bunyan
$ npm i --save bunyan-opbeat
Use
var bunyan = require('bunyan')
var BunyanOpbeat = require('bunyan-opbeat')
var log = bunyan.createLogger({
name: 'my-logger',
streams: [
{
level: 'warn',
type: 'raw',
stream: new BunyanOpbeat({
config: {
appId: '...',
organizationId: '...',
secretToken: '...',
}
})
}
]
})
log.error(new Error('whoops'))
Alternatively, if you've already started an opbeat instance somewhere else in your code, you can pass it directly to bunyan-opbeat and it will use it instead:
var bunyan = require('bunyan')
var BunyanOpbeat = require('bunyan-opbeat')
var opbeat = require('opbeat').start({
appId: '...',
organizationId: '...',
secretToken: '...'
})
var log = bunyan.createLogger({
name: 'my-logger',
streams: [
{
level: 'warn',
type: 'raw',
stream: new BunyanOpbeat({
client: opbeat
})
}
]
})
log.error(new Error('whoops'))
- note:
bunyan-opbeat
requires opbeat
client version >= 4.8.0
How does it work?
bunyan-opbeat reads data coming from your bunyan logger and uses opbeat.captureError()
to post it to Opbeat.
It will do it's best to pass on some common fields like user
, time
, hostname
and level
.
Anything else in your logs that opbeat can't understand will be passed as an extra
field