class Depthcharge::RequestLogger

Attributes

body[R]
env[R]
headers[R]
status[R]

Public Class Methods

new(env, status, headers, body) click to toggle source
# File lib/depthcharge/request_logger.rb, line 9
def initialize(env, status, headers, body)
  @env = env
  @status = status
  @headers = headers
  @body = body
end

Public Instance Methods

construct_log_entry() click to toggle source
# File lib/depthcharge/request_logger.rb, line 25
def construct_log_entry
  output = ""
  output << blank_line(0)
  output << format_line("#{env["REQUEST_METHOD"]} #{status} #{env["PATH_INFO"].inspect} at #{Time.now}", 0)
  output << format_hash("PARAMS", request_params(env))
  output << blank_line
  output << format_hash("REQUEST HEADERS", request_headers(env))
  output << blank_line
  output << format_line("RESPONSE STATUS: #{status}")
  output << blank_line
  output << format_hash("RESPONSE HEADERS", headers)
  output << blank_line
  output << format_line("BODY:")
  output << format_body(headers, body, 2)
  output << blank_line
  output << blank_line(0)
end
log(*outputs) click to toggle source
# File lib/depthcharge/request_logger.rb, line 16
def log(*outputs)
  log_entry = construct_log_entry

  outputs.flatten.each do |output|
    output.puts(log_entry)
    output.flush
  end
end