2017-12-24 05:34:47 +00:00
|
|
|
const util = require('util')
|
|
|
|
const winston = require('winston')
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Bugsnag
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
key: 'bugsnag',
|
|
|
|
title: 'Bugsnag',
|
|
|
|
props: ['key'],
|
|
|
|
init (logger, conf) {
|
|
|
|
let BugsnagLogger = winston.transports.BugsnagLogger = function (options) {
|
|
|
|
this.name = 'bugsnagLogger'
|
|
|
|
this.level = options.level || 'warn'
|
|
|
|
this.bugsnag = require('bugsnag')
|
|
|
|
this.bugsnag.register(options.key)
|
|
|
|
}
|
|
|
|
util.inherits(BugsnagLogger, winston.Transport)
|
|
|
|
|
|
|
|
BugsnagLogger.prototype.log = function (level, msg, meta, callback) {
|
|
|
|
this.bugsnag.notify(new Error(msg), _.assignIn(meta, { severity: level }))
|
|
|
|
callback(null, true)
|
|
|
|
}
|
|
|
|
|
2018-03-12 04:09:54 +00:00
|
|
|
logger.add(new BugsnagLogger({
|
2017-12-24 05:34:47 +00:00
|
|
|
level: 'warn',
|
|
|
|
key: conf.key
|
2018-03-12 04:09:54 +00:00
|
|
|
}))
|
2017-12-24 05:34:47 +00:00
|
|
|
}
|
|
|
|
}
|