Class: Rack::XrkLog::Dispose

Inherits:
Base
  • Object
show all
Defined in:
lib/rack/xrk/adapter/dispose.rb

Instance Attribute Summary

Attributes inherited from Base

#app, #app_name, #begin_at, #log_type, #logger

Instance Method Summary collapse

Methods inherited from Base

#stop_at, #total_runtime, #write

Constructor Details

#initialize(app, app_name) ⇒ Dispose

Returns a new instance of Dispose.



7
8
9
10
# File 'lib/rack/xrk/adapter/dispose.rb', line 7

def initialize(app, app_name)
  @app_name = app_name
  super
end

Instance Method Details

#formatter(env, body, status, header) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rack/xrk/adapter/dispose.rb', line 12

def formatter(env, body, status, header)
  @request = Rack::Request.new(env)

  return if [%r{^/assets/}, %r{favicon.ico}, %r{404}].any?{|path| path.match(@request.path) }

  client_ip_and_port    = "#{@request.ip}:0"
  server_ip_and_port    = "#{env['SERVER_NAME']}:#{env['SERVER_PORT']}"
  query_string          = @request.query_string.blank? ? "" : @request.query_string

  [
    client_ip_and_port,
    server_ip_and_port,
    total_runtime,
    @request.scheme,
    (query_string.bytesize rescue nil) || 0,
    (body[0].bytesize() rescue nil) || 0,
    @request.request_method,
    @request.path_info,
    status,
    query_string,
    path_parameters(env),
    "-",
    (json_with_nil(body[0]) rescue nil) || "-"
  ].join("|")
end

#json_with_nil(value) ⇒ Object



38
39
40
# File 'lib/rack/xrk/adapter/dispose.rb', line 38

def json_with_nil(value)
  JSON.parse(value).to_json
end

#path_parameters(env) ⇒ Object



42
43
44
45
# File 'lib/rack/xrk/adapter/dispose.rb', line 42

def path_parameters(env)
  opts = env["action_dispatch.request.path_parameters"]
  return "#{opts[:controller]}/#{opts[:action]}" unless opts.blank?
end