Skip to content

Instantly share code, notes, and snippets.

@andxyz
Created July 3, 2015 15:58
Show Gist options
  • Save andxyz/bbd58d7031ae0522a2c9 to your computer and use it in GitHub Desktop.
Save andxyz/bbd58d7031ae0522a2c9 to your computer and use it in GitHub Desktop.
module SearchApp
class ElasticSearchClient
def self.production_client
Elasticsearch::Client.new
end
def self.debug_client
@client = Elasticsearch::Client.new log: true
@client.transport.logger = Logger.new($stdout)
@client.transport.logger.progname = 'ElasticSearchClient'
@client.transport.logger.formatter = proc do |serverity, time, progname, msg|
puts ["[#{time.utc.iso8601}]", serverity, progname, format_msg(msg)].join(' ')
end
@client
end
private
# requests start with "> "
# responses start with "< "
def self.format_msg(msg)
if msg.start_with?('< ')
'< ' + JSON.pretty_generate(JSON.parse(msg[2..-1]))
elsif msg.start_with?('> ')
'> ' + JSON.pretty_generate(JSON.parse(msg[2..-1]))
else
msg
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment