Class: F4w::Rack::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/f4w/rack/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Logger

Returns a new instance of Logger.



7
8
9
# File 'lib/f4w/rack/logger.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/f4w/rack/logger.rb', line 11

def call(env)
  req = ::Rack::Request.new(env)
  requested_uri = req.url
  user_id = env['rack.oauth2.resource_owner']
  data = app_data(env)
  puts F4w::Logging::Entry.request_start(requested_uri, user_id, data)
  begin
    status, headers, body = @app.call(env)

    [status, headers, body]
  rescue Exception => e
    puts F4w::Logging::Entry.error(requested_uri, user_id, 'uncatched_exception', e.message, data.merge(error_class: e.class))
    throw e
  ensure
    puts F4w::Logging::Entry.request_end(requested_uri, user_id, data)
  end
end