module Fauna::ClientLogger

Example observer that can be used for debugging

Public Class Methods

logger() { |show_request_result(request_result)| ... } click to toggle source

Lambda that can be the observer for a Client. Will call the passed block on a string representation of each RequestResult.

Example:

logger = ClientLogger.logger do |str|
  puts str
end
Client.new observer: logger, ...
# File lib/fauna/client_logger.rb, line 14
def self.logger
  lambda do |request_result|
    yield show_request_result(request_result)
  end
end
show_request_result(request_result) click to toggle source

Translates a RequestResult to a string suitable for logging.

# File lib/fauna/client_logger.rb, line 21
def self.show_request_result(request_result)
  rr = request_result
  logged = ''

  logged << "Fauna #{rr.method.to_s.upcase} /#{rr.path}#{query_string_for_logging(rr.query)}\n"
  logged << "  Credentials: #{rr.auth}\n"
  if rr.request_content
    logged << "  Request JSON: #{indent(FaunaJson.to_json_pretty(rr.request_content))}\n"
  end
  logged << "  Response headers: #{indent(FaunaJson.to_json_pretty(rr.response_headers))}\n"
  logged << "  Response JSON: #{indent(FaunaJson.to_json_pretty(rr.response_content))}\n"
  logged << "  Response (#{rr.status_code}): Network latency #{(rr.time_taken * 1000).to_i}ms"

  logged
end