You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
804 B

  1. const util = require('util')
  2. const winston = require('winston')
  3. // ------------------------------------
  4. // Sentry
  5. // ------------------------------------
  6. module.exports = {
  7. init (logger, conf) {
  8. let SentryLogger = winston.transports.SentryLogger = function (options) {
  9. this.name = 'sentryLogger'
  10. this.level = options.level || 'warn'
  11. this.raven = require('raven')
  12. this.raven.config(options.key).install()
  13. }
  14. util.inherits(SentryLogger, winston.Transport)
  15. SentryLogger.prototype.log = function (level, msg, meta, callback) {
  16. level = (level === 'warn') ? 'warning' : level
  17. this.raven.captureMessage(msg, { level, extra: meta })
  18. callback(null, true)
  19. }
  20. logger.add(new SentryLogger({
  21. level: 'warn',
  22. key: conf.key
  23. }))
  24. }
  25. }