Class: Elastictastic::Middleware::LogRequests

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/elastictastic/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ LogRequests

Returns a new instance of LogRequests.



55
56
57
58
# File 'lib/elastictastic/middleware.rb', line 55

def initialize(app, logger)
  super(app)
  @logger = logger
end

Instance Method Details

#call(env) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/elastictastic/middleware.rb', line 60

def call(env)
  now = Time.now
  body = env[:body]
  @app.call(env).on_complete do
    method = env[:method].to_s.upcase
    time = ((Time.now - now) * 1000).to_i
    message = "ElasticSearch #{method} (#{time}ms) #{env[:url].path}"
    message << ' ' << body if body
    @logger.debug(message)
  end
end