module HTTPX::Loggable

  1. lib/httpx/loggable.rb

Methods

Public Instance

  1. log
  2. log_exception

Constants

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

Public Instance methods

log(level: @options.debug_level, color: nil, &msg)
[show source]
   # File lib/httpx/loggable.rb
16 def log(level: @options.debug_level, color: nil, &msg)
17   return unless @options.debug
18   return unless @options.debug_level >= level
19 
20   debug_stream = @options.debug
21 
22   message = (+"" << msg.call << "\n")
23   message = "\e[#{COLORS[color]}m#{message}\e[0m" if color && debug_stream.respond_to?(:isatty) && debug_stream.isatty
24   debug_stream << message
25 end
log_exception(ex, level: @options.debug_level, color: nil)
[show source]
   # File lib/httpx/loggable.rb
27 def log_exception(ex, level: @options.debug_level, color: nil)
28   return unless @options.debug
29   return unless @options.debug_level >= level
30 
31   log(level: level, color: color) { ex.full_message }
32 end