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.

32 lines
856 B

  1. const util = require('util')
  2. const winston = require('winston')
  3. const _ = require('lodash')
  4. // ------------------------------------
  5. // Bugsnag
  6. // ------------------------------------
  7. module.exports = {
  8. key: 'bugsnag',
  9. title: 'Bugsnag',
  10. props: ['key'],
  11. init (logger, conf) {
  12. let BugsnagLogger = winston.transports.BugsnagLogger = function (options) {
  13. this.name = 'bugsnagLogger'
  14. this.level = options.level || 'warn'
  15. this.bugsnag = require('bugsnag')
  16. this.bugsnag.register(options.key)
  17. }
  18. util.inherits(BugsnagLogger, winston.Transport)
  19. BugsnagLogger.prototype.log = function (level, msg, meta, callback) {
  20. this.bugsnag.notify(new Error(msg), _.assignIn(meta, { severity: level }))
  21. callback(null, true)
  22. }
  23. logger.add(BugsnagLogger, {
  24. level: 'warn',
  25. key: conf.key
  26. })
  27. }
  28. }