Class: Lograge::Formatters::L2met

Inherits:
KeyValue
  • Object
show all
Defined in:
lib/lograge/formatters/l2met.rb

Constant Summary collapse

L2MET_FIELDS =
[
  :method, :path, :format, :source, :status, :error,
  :duration, :view, :db, :location
]

Instance Method Summary collapse

Instance Method Details

#call(data) ⇒ Object



11
12
13
# File 'lib/lograge/formatters/l2met.rb', line 11

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

#fields_to_display(data) ⇒ Object



21
22
23
# File 'lib/lograge/formatters/l2met.rb', line 21

def fields_to_display(data)
  L2MET_FIELDS + (data.keys - L2MET_FIELDS) - [:controller, :action]
end

#format(key, value) ⇒ Object



15
16
17
18
19
# File 'lib/lograge/formatters/l2met.rb', line 15

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

  super(key, value)
end

#modify_payload(data) ⇒ Object



25
26
27
28
29
# File 'lib/lograge/formatters/l2met.rb', line 25

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

  data
end

#source_field(data) ⇒ Object



31
32
33
# File 'lib/lograge/formatters/l2met.rb', line 31

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