class Pushing::LogSubscriber

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

Public Instance Methods

deliver(event) click to toggle source

A notification was delivered.

# 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
logger() click to toggle source

Use the logger configured for Pushing::Base.

# File lib/pushing/log_subscriber.rb, line 38
def logger
  Pushing::Base.logger
end
process(event) click to toggle source

A notification was generated.

# 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