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