class Tennpipes::Logger::Rack

Tennpipes::Logger::Rack forwards every request to an app given, and logs a line in the Apache common log format to the logger, or rack.errors by default.

Public Class Methods

new(app, uri_root) click to toggle source
# File lib/tennpipes-base/logger.rb, line 444
def initialize(app, uri_root)
  @app = app
  @uri_root = uri_root.sub(/\/$/,"")
end

Public Instance Methods

call(env) click to toggle source
# File lib/tennpipes-base/logger.rb, line 449
def call(env)
  env['rack.logger'] = Tennpipes.logger
  began_at = Time.now
  status, header, body = @app.call(env)
  log(env, status, header, began_at) if logger.debug?
  [status, header, body]
end

Private Instance Methods

code_to_name(status) click to toggle source
# File lib/tennpipes-base/logger.rb, line 478
def code_to_name(status)
  ::Rack::Utils::HTTP_STATUS_CODES[status.to_i] || ''
end
log(env, status, header, began_at) click to toggle source
# File lib/tennpipes-base/logger.rb, line 459
def log(env, status, header, began_at)
  return if env['sinatra.static_file'] && (!logger.respond_to?(:log_static) || !logger.log_static)
  logger.bench(
    env["REQUEST_METHOD"],
    began_at,
    [
      @uri_root.to_s,
      env["PATH_INFO"],
      env["QUERY_STRING"].empty? ? "" : "?" + env["QUERY_STRING"],
      ' - ',
      logger.colorize(status.to_s[0..3], :default, :bold),
      ' ',
      code_to_name(status)
    ] * '',
    :debug,
    :magenta
  )
end