Sha256: f035a915c54ba6cdd0dfaab1f17440d6be3fd0a0ac8ccdd9dbbf8dd4acf2e432

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

module LogSanity
  module LogSubscriber
    class ActionDispatch < Base

      def request(event)
        payload = event.payload
        return if payload[:silence]

        info do
          request = payload[:request]
          response = payload[:response]
          method = payload[:method] || (request.request_method rescue nil) || 'UNKNOWN'
          f2 = {
            'at' => event_start(event),
            'event' => "#{request.scheme}_#{method.downcase}",
            'ip' => request.remote_ip,
            'rq' => request.uuid,
            # 'params' => request.filtered_params,
            # 'path' => request.filtered_path,
          }

          # unless fields['route']
          #   # most errors repopulate path, so look for the original one first.
          #   # original_path is, however, unfiltered.
          #   fields['path'] = payload[:env]['action_dispatch.original_path']
          #   fields['path'] ||= request.filtered_path
          # end

          fields['duration'] ||= {}
          fields['duration']['total'] = event.duration.round
            # rewrites 'total', which includes more of time spent in middleware
          fields['status'] ||= response[0].to_i if response
          compute_tags(request)
          f2.merge fields
        end
      end


      private

      def compute_tags(request)
        Rails.application.config.log_tags.each_with_index do |tag, idx|
          res = case tag
          when Proc
            tag.call(request)
          when Symbol
            request.send(tag)
          else
            tag
          end
          if res.is_a?(Hash)
            fields.deep_merge!(res)
          elsif tag.is_a? Symbol
            log tag.to_s, res
          else
            log "tag#{idx}", res
          end
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
log_sanity-1.3.2 lib/log_sanity/log_subscribers/action_dispatch.rb
log_sanity-1.3.1 lib/log_sanity/log_subscribers/action_dispatch.rb
log_sanity-1.3.0 lib/log_sanity/log_subscribers/action_dispatch.rb
log_sanity-1.2.0 lib/log_sanity/log_subscribers/action_dispatch.rb