Sha256: 948387869cba00129325d84c988f21974ac98276f165caa9a02200bec06c0005

Contents?: true

Size: 841 Bytes

Versions: 20

Compression:

Stored size: 841 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Loggable
    COLORS = {
      black: 30,
      red: 31,
      green: 32,
      yellow: 33,
      blue: 34,
      magenta: 35,
      cyan: 36,
      white: 37,
    }.freeze

    def log(level: @options.debug_level, color: nil, &msg)
      return unless @options.debug
      return unless @options.debug_level >= level

      debug_stream = @options.debug

      message = (+"" << msg.call << "\n")
      message = "\e[#{COLORS[color]}m#{message}\e[0m" if color && debug_stream.respond_to?(:isatty) && debug_stream.isatty
      debug_stream << message
    end

    def log_exception(ex, level: @options.debug_level, color: nil)
      return unless @options.debug
      return unless @options.debug_level >= level

      log(level: level, color: color) { ex.full_message }
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/loggable.rb
httpx-1.3.3 lib/httpx/loggable.rb
httpx-1.3.2 lib/httpx/loggable.rb
httpx-1.3.1 lib/httpx/loggable.rb
httpx-1.3.0 lib/httpx/loggable.rb
httpx-1.2.6 lib/httpx/loggable.rb
httpx-1.2.4 lib/httpx/loggable.rb
httpx-1.2.3 lib/httpx/loggable.rb
httpx-1.2.2 lib/httpx/loggable.rb
httpx-1.2.1 lib/httpx/loggable.rb
httpx-1.2.0 lib/httpx/loggable.rb
httpx-1.1.5 lib/httpx/loggable.rb
httpx-1.1.4 lib/httpx/loggable.rb
httpx-1.1.3 lib/httpx/loggable.rb
httpx-1.1.2 lib/httpx/loggable.rb
httpx-1.1.1 lib/httpx/loggable.rb
httpx-1.1.0 lib/httpx/loggable.rb
httpx-1.0.2 lib/httpx/loggable.rb
httpx-1.0.1 lib/httpx/loggable.rb
httpx-1.0.0 lib/httpx/loggable.rb