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, label: "", color: nil, &msg)
[show source]
   # File lib/httpx/loggable.rb
16 def log(level: @options.debug_level, label: "", color: nil, &msg)
17   return unless @options.debug
18   return unless @options.debug_level >= level
19 
20   debug_stream = @options.debug
21 
22   message = (+label << msg.call << "\n")
23   message = "\e[#{COLORS[color]}m#{message}\e[0m" if debug_stream.respond_to?(:isatty) && debug_stream.isatty
24   debug_stream << message
25 end
log_exception (ex, level: @options.debug_level, label: "", color: nil)
[show source]
   # File lib/httpx/loggable.rb
29 def log_exception(ex, level: @options.debug_level, label: "", color: nil)
30   return unless @options.debug
31   return unless @options.debug_level >= level
32 
33   message = +"#{ex.message} (#{ex.class})"
34   message << "\n" << ex.backtrace.join("\n") unless ex.backtrace.nil?
35   log(level: level, label: label, color: color) { message }
36 end