Class: Pushing::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/pushing/log_subscriber.rb

Overview

Implements the ActiveSupport::LogSubscriber for logging notifications when a push notification is delivered.

Instance Method Summary collapse

Instance Method Details

#deliver(event) ⇒ Object

A notification was delivered.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pushing/log_subscriber.rb', line 9

def deliver(event)
  return unless logger.info?

  event.payload[:notification].each do |platform, payload|
    info do
      recipients = payload.recipients.map {|r| r.truncate(32) }.join(", ")
      "  #{platform.upcase}: sent push notification to #{recipients} (#{event.duration.round(1)}ms)"
    end

    next unless logger.debug?
    debug do
      "Payload:\n#{JSON.pretty_generate(payload.payload).indent(2)}\n".indent(2)
    end
  end
end

#loggerObject

Use the logger configured for Pushing::Base.



38
39
40
# File 'lib/pushing/log_subscriber.rb', line 38

def logger
  Pushing::Base.logger
end

#process(event) ⇒ Object

A notification was generated.



26
27
28
29
30
31
32
33
34
35
# File 'lib/pushing/log_subscriber.rb', line 26

def process(event)
  return unless logger.debug?

  debug do
    notifier = event.payload[:notifier]
    action   = event.payload[:action]

    "#{notifier}##{action}: processed outbound push notification in #{event.duration.round(1)}ms"
  end
end