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'.freeze
SINATRA_ERROR =
'sinatra.error'.freeze
HTTP_VERSION =
'HTTP_VERSION'.freeze
PATH_INFO =
'PATH_INFO'.freeze
REQUEST_METHOD =
'REQUEST_METHOD'.freeze
QUERY_STRING =
'QUERY_STRING'.freeze
CONTENT_LENGTH =
'Content-Length'.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Logger.



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

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



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

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