Sha256: 07a33442e56e761c8da4b458be1c324e25c4c1e715dbab88699d7ca8317b1287

Contents?: true

Size: 903 Bytes

Versions: 14

Compression:

Stored size: 903 Bytes

Contents

require 'active_support/core_ext/class/attribute'
require 'active_support/log_subscriber'

module LogStasher
  module ActiveSupport
    class MailerLogSubscriber < ::ActiveSupport::LogSubscriber
      MAILER_FIELDS = [:mailer, :action, :message_id, :from, :to]

      def deliver(event)
        process_event(event, ['mailer', 'deliver'])
      end

      def receive(event)
        process_event(event, ['mailer', 'receive'])
      end

      def process(event)
        process_event(event, ['mailer', 'process'])
      end

      def logger
        LogStasher.logger
      end

      private

      def process_event(event, tags)
        data = LogStasher.request_context.merge(extract_metadata(event.payload))
        logger << LogStasher.build_logstash_event(data, tags).to_json + "\n"
      end

      def extract_metadata(payload)
        payload.slice(*MAILER_FIELDS)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
logstasher-1.4.0 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.3.0 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.2.2 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.2.1 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.2.0 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.1.1 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.1.0 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.0.1 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-1.0.0 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-0.9.0 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-0.8.6 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-0.8.5 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-0.8.2 lib/logstasher/active_support/mailer_log_subscriber.rb
logstasher-0.8.0 lib/logstasher/active_support/mailer_log_subscriber.rb