2017-12-24 05:34:47 +00:00
|
|
|
const util = require('util')
|
|
|
|
const winston = require('winston')
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Rollbar
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
key: 'rollbar',
|
|
|
|
title: 'Rollbar',
|
|
|
|
props: ['key'],
|
|
|
|
init (logger, conf) {
|
|
|
|
let RollbarLogger = winston.transports.RollbarLogger = function (options) {
|
|
|
|
this.name = 'rollbarLogger'
|
|
|
|
this.level = options.level || 'warn'
|
|
|
|
this.rollbar = require('rollbar')
|
|
|
|
this.rollbar.init(options.key)
|
|
|
|
}
|
|
|
|
util.inherits(RollbarLogger, winston.Transport)
|
|
|
|
|
|
|
|
RollbarLogger.prototype.log = function (level, msg, meta, callback) {
|
|
|
|
this.rollbar.handleErrorWithPayloadData(new Error(msg), _.assignIn(meta, { level }))
|
|
|
|
callback(null, true)
|
|
|
|
}
|
|
|
|
|
2018-03-12 04:09:54 +00:00
|
|
|
logger.add(new RollbarLogger({
|
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
|
|
|
}
|
|
|
|
}
|