Sha256: 2bec77b8946b77d8c4e406a15c3e4dcf096f5525c4e1c62a42e00c17b5aafe3b

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

require 'lograge/formatters/key_value'

module Lograge
  module Formatters
    class L2met < KeyValue
      L2MET_FIELDS = [
        :method,
        :path,
        :format,
        :source,
        :status,
        :error,
        :duration,
        :view,
        :db,
        :location
      ].freeze

      UNWANTED_FIELDS = [
        :controller,
        :action
      ].freeze

      def call(data)
        super(modify_payload(data))
      end

      protected

      def fields_to_display(data)
        L2MET_FIELDS + additional_fields(data)
      end

      def additional_fields(data)
        (data.keys - L2MET_FIELDS) - UNWANTED_FIELDS
      end

      def format(key, value)
        key = "measure#page.#{key}" if value.is_a?(Float)

        super(key, value)
      end

      def modify_payload(data)
        data[:source] = source_field(data) if data[:controller] && data[:action]

        data
      end

      def source_field(data)
        "#{data[:controller].to_s.tr('/', '-')}:#{data[:action]}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lograge-0.11.2 lib/lograge/formatters/l2met.rb
lograge-0.11.1 lib/lograge/formatters/l2met.rb
lograge-0.11.0 lib/lograge/formatters/l2met.rb
lograge-0.10.0 lib/lograge/formatters/l2met.rb