class Deas::BaseLogging

Public Class Methods

new(app, logger) click to toggle source
# File lib/deas/logging.rb, line 14
def initialize(app, logger)
  @app    = app
  @logger = logger
end

Public Instance Methods

call(env) click to toggle source

The Rack call interface. The receiver acts as a prototype and runs each request in a clone object unless the rack.run_once variable is set in the environment. Ripped from: github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/context.rb

# File lib/deas/logging.rb, line 23
def call(env)
  if env['rack.run_once']
    call! env
  else
    clone.call! env
  end
end
call!(env) click to toggle source

The real Rack call interface. This is the common behavior for both the verbose and summary logging middlewares. It sets rack's logger, times the response and returns it as is.

# File lib/deas/logging.rb, line 34
def call!(env)
  env['rack.logger'] = @logger

  status, headers, body = nil, nil, nil
  benchmark = Benchmark.measure do
    status, headers, body = @app.call(env)
  end
  log_error(env['deas.error'])
  env['deas.time_taken'] = RoundedTime.new(benchmark.real)

  [status, headers, body]
end
log(message) click to toggle source
# File lib/deas/logging.rb, line 47
def log(message)
  @logger.info "[Deas] #{message}"
end
log_error(exception) click to toggle source
# File lib/deas/logging.rb, line 51
def log_error(exception)
  return if !exception
  log "#{exception.class}: #{exception.message}\n" \
      "#{(exception.backtrace || []).join("\n")}"
end