Module: HTTPX::Loggable
- Included in:
- Connection, Connection::HTTP1, Connection::HTTP2, ErrorResponse, Resolver::Resolver, Session, TCP, UDP
- Defined in:
- lib/httpx/loggable.rb
Constant Summary collapse
- COLORS =
{ black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, }.freeze
- USE_DEBUG_LOG =
ENV.key?("HTTPX_DEBUG")
Instance Method Summary collapse
- #log(level: @options.debug_level, color: nil, &msg) ⇒ Object
- #log_exception(ex, level: @options.debug_level, color: nil) ⇒ Object
Instance Method Details
#log(level: @options.debug_level, color: nil, &msg) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/httpx/loggable.rb', line 18 def log(level: @options.debug_level, color: nil, &msg) return unless @options.debug_level >= level debug_stream = @options.debug || ($stderr if USE_DEBUG_LOG) return unless debug_stream = (+"" << msg.call << "\n") = "\e[#{COLORS[color]}m#{}\e[0m" if color && debug_stream.respond_to?(:isatty) && debug_stream.isatty debug_stream << end |
#log_exception(ex, level: @options.debug_level, color: nil) ⇒ Object
30 31 32 |
# File 'lib/httpx/loggable.rb', line 30 def log_exception(ex, level: @options.debug_level, color: nil) log(level: level, color: color) { ex. } end |