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

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