Class: Hubbado::Log::NotifyRollbar

Inherits:
LogHandler show all
Defined in:
lib/hubbado/log/notify_rollbar.rb

Overview

Forwards a log line worth an incident to Rollbar.

Constant Summary collapse

LEVELS =

Rollbar's own levels. It has none above error, so the two severities above warn share it, and anything below a warning is running commentary that reaches the handlers which print rather than this one.

{ warn: :warn, error: :error, fatal: :error, unknown: :error }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(notifier: nil) ⇒ NotifyRollbar

Returns a new instance of NotifyRollbar.



14
15
16
17
18
# File 'lib/hubbado/log/notify_rollbar.rb', line 14

def initialize(notifier: nil)
  super()

  @notifier = notifier
end

Instance Method Details

#log(subject, severity, message, data = nil, stacktrace = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/hubbado/log/notify_rollbar.rb', line 20

def log(subject, severity, message, data = nil, stacktrace = nil)
  level = LEVELS[severity.to_sym]
  return if level.nil?

  error = data if data.is_a?(::Exception)

  notifier.public_send(
    level, *[error, title(message), extra(subject, data, stacktrace)].compact
  )
end