Sha256: 73acaea68fc24610a7db7cae4d219f25b5ac9e75c4cbcfb0f9b8b4577ee18d09
Contents?: true
Size: 1.12 KB
Versions: 37
Compression:
Stored size: 1.12 KB
Contents
module ZendeskAPI module Middleware module Response # Faraday middleware to handle logging # @private class Logger < Faraday::Middleware LOG_LENGTH = 1000 def initialize(app, logger = nil) super(app) @logger = logger || begin require 'logger' ::Logger.new(STDOUT) end end def call(env) @logger.info "#{env[:method]} #{env[:url].to_s}" @logger.debug dump_debug(env, :request_headers) @app.call(env).on_complete do |env| info = "Status #{env[:status]}" info.concat(" #{env[:body].to_s[0, LOG_LENGTH]}") if (400..499).cover?(env[:status].to_i) @logger.info info @logger.debug dump_debug(env, :response_headers) end end private def dump_debug(env, headers_key) info = env[headers_key].map { |k, v| " #{k}: #{v.inspect}" }.join("\n") unless env[:body].nil? info.concat("\n") info.concat(env[:body].inspect) end info end end end end end
Version data entries
37 entries across 37 versions & 2 rubygems