Sha256: 512887a44e048dfc63bb83d5893dd469a7745fd408c45d26718fc9396474c489

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'rollbar'
require 'rollbar_helper/version'

module RollbarHelper
  LEVELS = [
    :critical,
    :debug,
    :error,
    :info,
    :warning,
  ]

  class << self
    def critical(obj, fingerprint: nil, **data)
      log(:critical, obj, :callee => caller, fingerprint: fingerprint, **data)
    end

    def debug(obj, fingerprint: nil, **data)
      log(:debug, obj, :callee => caller, fingerprint: fingerprint, **data)
    end

    def error(obj, fingerprint: nil, **data)
      log(:error, obj, :callee => caller, fingerprint: fingerprint, **data)
    end

    def info(obj, fingerprint: nil, **data)
      log(:info, obj, :callee => caller, fingerprint: fingerprint, **data)
    end

    def warn(obj, fingerprint: nil, **data)
      log(:warning, obj, :callee => caller, fingerprint: fingerprint, **data)
    end

    def warning(obj, fingerprint: nil, **data)
      log(:warning, obj, :callee => caller, fingerprint: fingerprint, **data)
    end

    def log(level, obj, callee: caller, fingerprint: nil, **data)
      level = level.to_sym
      raise ArgumentError, 'Log level is not supported' unless LEVELS.include?(level)
      e = nil

      if obj.is_a?(Exception)
        e = obj
      else
        e = StandardError.new(obj.to_s)
        e.set_backtrace(callee)
      end

      unless fingerprint.nil?
        ::Rollbar.scope(:fingerprint => fingerprint).send(level, e, data)
      else
        ::Rollbar.send(level, e, data)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rollbar_helper-1.0.0 lib/rollbar_helper.rb
rollbar_helper-0.3.0 lib/rollbar_helper.rb