Class: Rack::RequestLogger

Inherits:
RackLogger show all
Defined in:
lib/simple_rack_logger/request_logger.rb

Instance Attribute Summary

Attributes inherited from RackLogger

#logger

Instance Method Summary collapse

Methods inherited from RackLogger

flush

Constructor Details

#initialize(app, logger, *filters) ⇒ RequestLogger

Returns a new instance of RequestLogger.



6
7
8
# File 'lib/simple_rack_logger/request_logger.rb', line 6

def initialize(app, logger, *filters)
  super
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_rack_logger/request_logger.rb', line 10

def call(env)

  uuid = unique_identy

  request = Rack::Request.new(env)
  block   = @filters.select { |filter| filter.respond_to?(:filter) && filter.send(:filter, request) }
  if block.empty?
    logger.info("IDENT:|#{uuid}| REQUEST_VALUE:|#{expose(request, env)}|")
    logger.flush
  end

  return_value = @app.call(env)

  if block.empty?
    logger.info("IDENT:|#{uuid}| RETURN_VALUE:|#{expose_return(return_value).to_s}|")
    logger.flush
  end

  return_value
end