lib/rollbar_helper.rb in rollbar_helper-0.2.0 vs lib/rollbar_helper.rb in rollbar_helper-0.3.0

- old
+ new

@@ -1,24 +1,57 @@ -class RollbarHelper - VERSION = "0.2.0" +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(caller) + e.set_backtrace(callee) end - if fingerprint.present? - Rollbar.scope(:fingerprint => fingerprint).error(e, data) + unless fingerprint.nil? + ::Rollbar.scope(:fingerprint => fingerprint).send(level, e, data) else - Rollbar.error(e, data) + ::Rollbar.send(level, e, data) end end - end end