Sha256: 220cb8fb832dc8e6fd3e5c2b94cf44d342669d20e5f5f2c8e322574e0f325799

Contents?: true

Size: 929 Bytes

Versions: 3

Compression:

Stored size: 929 Bytes

Contents

require 'active_support/log_subscriber'

module SmsCarrier
  # Implements the ActiveSupport::LogSubscriber for logging notifications when
  # sms is delivered or received.
  class LogSubscriber < ActiveSupport::LogSubscriber
    # An SMS was delivered.
    def deliver(event)
      info do
        recipients = Array(event.payload[:to]).join(', ')
        "\nSent SMS to #{recipients} (#{event.duration.round(1)}ms)"
      end

      debug { event.payload[:sms] }
    end

    # An SMS was generated.
    def process(event)
      debug do
        carrier = event.payload[:carrier]
        action = event.payload[:action]
        "\n#{carrier}##{action}: processed outbound SMS in #{event.duration.round(1)}ms"
      end
    end

    # Use the logger configured for SmsCarrier::Base.
    def logger
      SmsCarrier::Base.logger
    end
  end
end

SmsCarrier::LogSubscriber.attach_to :sms_carrier

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sms_carrier-0.1.2 lib/sms_carrier/log_subscriber.rb
sms_carrier-0.1.1 lib/sms_carrier/log_subscriber.rb
sms_carrier-0.1.0 lib/sms_carrier/log_subscriber.rb