Class: PhobosDBCheckpoint::Middleware::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/phobos_db_checkpoint/middleware/logger.rb

Constant Summary collapse

RACK_LOGGER =
'rack.logger'
SINATRA_ERROR =
'sinatra.error'
HTTP_VERSION =
'HTTP_VERSION'
PATH_INFO =
'PATH_INFO'
REQUEST_METHOD =
'REQUEST_METHOD'
QUERY_STRING =
'QUERY_STRING'
CONTENT_LENGTH =
'Content-Length'

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Logger

Returns a new instance of Logger.



16
17
18
19
20
21
22
# File 'lib/phobos_db_checkpoint/middleware/logger.rb', line 16

def initialize(app, options = {})
  @app = app
  Phobos.configure(options.fetch(:config, 'config/phobos.yml'))
  Phobos.config.logger.file = options.fetch(:log_file, 'log/api.log')
  Phobos.configure_logger
  ActiveRecord::Base.logger = Phobos.logger
end

Instance Method Details

#call(request_env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/phobos_db_checkpoint/middleware/logger.rb', line 24

def call(request_env)
  began_at = Time.now
  request_env[RACK_LOGGER] = Phobos.logger
  status, header, body = @app.call(request_env)
  header = Rack::Utils::HeaderHash.new(header)
  body = Rack::BodyProxy.new(body) do
    log(request_env, status, header, began_at)
  end
  [status, header, body]
end