wikijs-fork/server/modules/logging/sentry/logger.js

30 lines
804 B
JavaScript
Raw Permalink Normal View History

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)
}
logger.add(new SentryLogger({
2017-12-24 05:34:47 +00:00
level: 'warn',
key: conf.key
}))
2017-12-24 05:34:47 +00:00
}
}