2017-12-24 05:34:47 +00:00
|
|
|
const util = require('util')
|
|
|
|
const winston = require('winston')
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Sentry
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init (logger, conf) {
|
2018-02-24 21:13:49 +00:00
|
|
|
let SentryLogger = winston.transports.SentryLogger = function (options) {
|
2017-12-24 05:34:47 +00:00
|
|
|
this.name = 'sentryLogger'
|
|
|
|
this.level = options.level || 'warn'
|
|
|
|
this.raven = require('raven')
|
|
|
|
this.raven.config(options.key).install()
|
|
|
|
}
|
|
|
|
util.inherits(SentryLogger, winston.Transport)
|
|
|
|
|
|
|
|
SentryLogger.prototype.log = function (level, msg, meta, callback) {
|
|
|
|
level = (level === 'warn') ? 'warning' : level
|
|
|
|
this.raven.captureMessage(msg, { level, extra: meta })
|
|
|
|
callback(null, true)
|
|
|
|
}
|
|
|
|
|
2018-03-12 04:09:54 +00:00
|
|
|
logger.add(new SentryLogger({
|
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
|
|
|
}
|
|
|
|
}
|