Class: Messages::HerokuRouter

Inherits:
MessageTypeMatcher show all
Defined in:
lib/log_query/messages/heroku_router.rb

Constant Summary collapse

ATTRIBUTES =

2016-10-12T11:54:02.902066+00:00 heroku: at=info method=GET path=“/javascript/[email protected]&locale=UK&name=Graham%20Dodgson” host=merrell.refer.gift request_id=bf7a23e0-3c5c-4df2-9eff-f7812d96f665 fwd=“62.252.0.138” dyno=web.1 connect=0ms service=126ms status=200 bytes=1414

[:sock, :at, :code, :desc, :method, :path, :host, :request_id, :fwd, :dyno, :connect, :service, :status, :bytes]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MessageTypeMatcher

===

Constructor Details

#initialize(message) ⇒ HerokuRouter

Returns a new instance of HerokuRouter.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/log_query/messages/heroku_router.rb', line 16

def initialize(message)
  ATTRIBUTES.
    select { |attr| message.include?(" #{attr}=") }.
    map do |attribute|
      value = message.match(/#{attribute}=([^\s]*|"[^"]*")/)[1]
      value = value.match(/"?([^"]*)"?/)[1]
      value = parse_value(value, attribute)
      [attribute, value]
    end.each do |(key, value)|
      instance_variable_set("@#{key}", value)
    end
end

Class Method Details

.attributesObject



12
13
14
# File 'lib/log_query/messages/heroku_router.rb', line 12

def self.attributes
  ATTRIBUTES
end

Instance Method Details

#parse_value(value, attribute) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/log_query/messages/heroku_router.rb', line 30

def parse_value(value, attribute)
  case attribute
  when :sock, :at, :code, :desc, :method, :host, :request_id, :fwd, :dyno, :status
    value
  when :path
    value.split('?')[0].gsub(/-[a-f0-9]{64}/, '')
  when :connect, :service
    Integer(value.match(/([0-9]*)ms/)[1])
  when :bytes
    Integer(value) rescue 0
  end
end