Class: Elastictastic::Middleware::LogRequests

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

Instance Method Summary collapse

Methods included from TransportMethods

#delete, #get, #head, #post, #put

Constructor Details

#initialize(connection, logger) ⇒ LogRequests

Returns a new instance of LogRequests.



82
83
84
85
# File 'lib/elastictastic/middleware.rb', line 82

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

Instance Method Details

#request(method, path, body = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/elastictastic/middleware.rb', line 87

def request(method, path, body = nil)
  now = Time.now
  super.tap do
    @logger.debug do
      time = ((Time.now - now) * 1000).to_i
      message = "ElasticSearch #{method.to_s.upcase} (#{time}ms) #{path}"
      message << ' ' << body if body
      message
    end
  end
end