Sha256: dd2ff510ffc6c5eac5695fb6ac56e41085a413e54c75c883bd17a1ffd8e8aa6d

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

module LogSanity
  module LogSubscriber
    class ActionController < Base
      INTERNAL_PARAMS = %w(controller action format _method only_path)

      def process_action(event)
        payload = event.payload
        params  = payload[:params].except(*INTERNAL_PARAMS)
        format  = payload[:format]

        # log 'method', payload[:method]
        # log 'path', payload[:path]
        # log 'controller', payload[:controller]
        # log 'action', payload[:action]
        log 'route', "#{payload[:controller]}##{payload[:action]}"
        log 'format', format
        log 'params', params if params.present?

        status = payload[:status]
        if status.nil? && payload[:exception].present?
          exception_class_name = payload[:exception].first
          status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
        end

        durations = {'total' => event.duration.round}
        queries   = {}
        additions = ::ActionController::Base.log_process_action(payload)
        additions.each do |add|
          if add =~ /^([^:]+):?\s*([0-9.]+)(ms)?/
            ms = $2.to_f.round
            name = $1.downcase
            durations[name] = ms if ms > 0
          end
          if name and add =~ /[^0-9]([0-9]+) quer/
            q_real = $1.to_i
            if q_real > 0 and add =~ /[^0-9]([0-9]+) cached/
              q_real -= $1.to_i # exclude cached queries
            end
            queries[name] = q_real if q_real > 0
          end
        end

        log 'queries', queries if queries.any?
        log 'duration', durations
        log 'status', status
      end

      def halted_callback(event)
        log 'filter_chain_halt', event.payload[:filter].inspect
      end

      def send_file(event)
        log 'send_file', event.payload[:path]
      end

      def redirect_to(event)
        log 'redirect', event.payload[:location]
      end

      def send_data(event)
        log 'send_data', event.payload[:filename] || 'binary'
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
log_sanity-2.3.0 lib/log_sanity/log_subscribers/action_controller.rb
log_sanity-2.2.0 lib/log_sanity/log_subscribers/action_controller.rb