Class: Rack::LTSVLogger

Inherits:
CommonLogger
  • Object
show all
Defined in:
lib/rack/ltsvlogger.rb,
lib/rack/ltsvlogger/version.rb

Constant Summary collapse

FORMAT =
%w[
  time
  host
  forwardedfor
  user
  method
  path
  query
  protocol
  status
  size
  runtime
].map{ |f| "#{f}:%{#{f}}" }.join("\t") + "\n"
VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#log(env, status, header, began_at) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack/ltsvlogger.rb', line 21

def log(env, status, header, began_at)
  now = Time.now
  length = extract_content_length(header)

  logger = @logger || env['rack.errors']
  logger.write FORMAT % {
    time: now.strftime("%d/%b/%Y %H:%M:%S"),
    host: env["REMOTE_ADDR"] || "-",
    forwardedfor: env['HTTP_X_FORWARDED_FOR'] || "-",
    user: env["REMOTE_USER"] || "-",
    method: env["REQUEST_METHOD"],
    path: env["PATH_INFO"],
    query: env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
    protocol: env["HTTP_VERSION"],
    status: status.to_s[0..3],
    size: length,
    runtime: now - began_at,
  }
end