Sha256: 3b4cd9a5eab55daa332fbed39b7512b8b1ab53d0276f9d703f591d7631b82e2c

Contents?: true

Size: 889 Bytes

Versions: 7

Compression:

Stored size: 889 Bytes

Contents

require 'logatron/logatron'

class Hyperion
  module Logger

    def logger
      Logatron
    end

    def with_request_logging(route, uri, headers)
      Logatron.log(msg: "Hyperion #{route.method.to_s.upcase} #{uri}") do |logger|
        log_headers(headers, logger)
        yield
      end
    end

    def log_result(result)
      logger.error(dump_json(result.as_json)) if should_log_result?(result)
    end

    def log_stub(rule)
      logger.debug "Stubbed #{rule.method.to_s.upcase} #{rule.path}"
      log_headers(rule.headers, logger)
    end

    private

    def log_headers(headers, logger)
      h = headers.delete_if { |_k, v| v.nil? }
      logger.info(dump_json(h))
    end

    def should_log_result?(result)
      result.body && result.status != HyperionStatus::SUCCESS
    end

    def dump_json(obj)
      Oj.dump(obj)
    rescue
      obj.inspect
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyperion_http-0.6.0 lib/hyperion/aux/logger.rb
hyperion_http-0.5.0 lib/hyperion/aux/logger.rb
hyperion_http-0.3.0 lib/hyperion/aux/logger.rb
hyperion_http-0.2.4 lib/hyperion/aux/logger.rb
hyperion_http-0.2.3 lib/hyperion/aux/logger.rb
hyperion_http-0.2.2 lib/hyperion/aux/logger.rb
hyperion_http-0.2.1 lib/hyperion/aux/logger.rb