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
866 B

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