Sha256: a62ca92b11179d4c605365cb220c56ec240b8e440ce8a85aed5831c8ad001443

Contents?: true

Size: 989 Bytes

Versions: 30

Compression:

Stored size: 989 Bytes

Contents

module Pupa
  class Processor
    module Middleware
      # Customizes the Faraday default logger.
      class Logger < FaradayMiddleware::ResponseMiddleware
        extend Forwardable

        def initialize(app, logger = nil)
          super(app)
          @logger = logger || begin
            require 'logger'
            ::Logger.new(STDOUT)
          end
        end

        def_delegators :@logger, :debug, :info, :warn, :error, :fatal

        def call(env)
          info "#{env[:method]} #{env[:url].to_s} #{env[:body].to_s}" # XXX add POST body
          debug('request') { dump_headers env[:request_headers] }
          super
        end

        def on_complete(env)
          debug('Status') { env[:status].to_s } # XXX switch from info
          debug('response') { dump_headers env[:response_headers] }
        end

        private

        def dump_headers(headers)
          headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
pupa-0.2.4 lib/pupa/processor/middleware/logger.rb
pupa-0.2.3 lib/pupa/processor/middleware/logger.rb
pupa-0.2.2 lib/pupa/processor/middleware/logger.rb
pupa-0.2.1 lib/pupa/processor/middleware/logger.rb
pupa-0.2.0 lib/pupa/processor/middleware/logger.rb
pupa-0.1.11 lib/pupa/processor/middleware/logger.rb
pupa-0.1.10 lib/pupa/processor/middleware/logger.rb
pupa-0.1.9 lib/pupa/processor/middleware/logger.rb
pupa-0.1.8 lib/pupa/processor/middleware/logger.rb
pupa-0.1.7 lib/pupa/processor/middleware/logger.rb
pupa-0.1.6 lib/pupa/processor/middleware/logger.rb
pupa-0.1.5 lib/pupa/processor/middleware/logger.rb
pupa-0.1.4 lib/pupa/processor/middleware/logger.rb
pupa-0.1.3 lib/pupa/processor/middleware/logger.rb
pupa-0.1.2 lib/pupa/processor/middleware/logger.rb
pupa-0.1.1 lib/pupa/processor/middleware/logger.rb
pupa-0.1.0 lib/pupa/processor/middleware/logger.rb
pupa-0.0.13 lib/pupa/processor/middleware/logger.rb
pupa-0.0.12 lib/pupa/processor/middleware/logger.rb
pupa-0.0.11 lib/pupa/processor/middleware/logger.rb