Class: RightSupport::Notifier::Logger

Inherits:
Base show all
Defined in:
lib/right_support/notifiers/logger.rb

Constant Summary collapse

MAX_PAYLOAD =

arbitrary upper bound on payload dumped to log output.

4096

Constants included from Log::Mixin

Log::Mixin::Decorator, Log::Mixin::UNDELEGATED

Instance Attribute Summary

Attributes inherited from Base

#backtrace_decoder

Instance Method Summary collapse

Methods inherited from Base

#debug_mode?, #initialize, #notifiable?

Methods included from Log::Mixin

default_logger, default_logger=, included

Constructor Details

This class inherits a constructor from RightSupport::Notifier::Base

Instance Method Details

#notify(notification) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/right_support/notifiers/logger.rb', line 30

def notify(notification)
  # payload is usually not logged unless DEBUG_MODE=true but for consistency
 	# we will always include it in the log with the error message.
  #
  # note that there is no payload blacklisting as access to view the logs in
  # production is already restricted. what is most important about
  # blacklisting data is that it not reach the less secure error notification
  # services where it is stored permanently.
  payload = notification.payload
  if payload.empty?
    payload = nil
  else
    payload = payload.inspect[0, MAX_PAYLOAD]
  end

  # we are interested in the root cause for logging purposes except when
  # DEBUG_MODE==true, in which case iterate over all causes without the limit
  # on backtrace size.
  if debug_mode?
    backtrace_decoder.walk_error(notification.error, raw_trace: true) do |cause|
      log_error(notification, cause, cause.backtrace, payload)
      payload = nil  # do not repeat payload
    end
  else
    cause, frames = backtrace_decoder.walk_error(notification.error)
    log_error(notification, cause, frames, payload)
  end
  true
rescue ::Exception => e
  lines = [e.class.name, e.message, e.backtrace].flatten.compact
  msg = "Failed to notify: #{lines.join("\n")}"
  logger.error(msg)
  true
end