Module: HTTPX::Loggable
- Included in:
- Connection, Connection::HTTP1, Connection::HTTP2, ErrorResponse, Request, Resolver::Resolver, Session, TCP, UDP
- Defined in:
- lib/httpx/loggable.rb,
sig/loggable.rbs
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")
Class Method Summary collapse
Instance Method Summary collapse
- #log(level: @options.debug_level, color: nil, debug_level: @options.debug_level, debug: @options.debug) { ... } ⇒ void
- #log_exception(ex, level: @options.debug_level, color: nil, debug_level: @options.debug_level, debug: @options.debug) ⇒ void
- #log_redact(text, should_redact = nil) ⇒ String
- #log_redact_body(text) ⇒ String
- #log_redact_headers(text) ⇒ String
Class Method Details
.log_identifiers ⇒ String
20 21 22 23 24 |
# File 'lib/httpx/loggable.rb', line 20 def self.log_identifiers "pid=#{Process.pid} " \ "tid=#{Thread.current.object_id} " \ "fid=#{Fiber.current.object_id}" end |
Instance Method Details
#log(level: @options.debug_level, color: nil, debug_level: @options.debug_level, debug: @options.debug) { ... } ⇒ void
This method returns an undefined value.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/httpx/loggable.rb', line 26 def log( level: @options.debug_level, color: nil, debug_level: @options.debug_level, debug: @options.debug, &msg ) return unless debug_level >= level debug_stream = debug || ($stderr if USE_DEBUG_LOG) return unless debug_stream klass = self.class until (class_name = klass.name) klass = klass.superclass end = +"(time=#{Time.now.utc} " \ "#{Loggable.log_identifiers} " \ "self=#{class_name}##{object_id}) " << 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, debug_level: @options.debug_level, debug: @options.debug) ⇒ void
This method returns an undefined value.
53 54 55 |
# File 'lib/httpx/loggable.rb', line 53 def log_exception(ex, level: @options.debug_level, color: nil, debug_level: @options.debug_level, debug: @options.debug) log(level: level, color: color, debug_level: debug_level, debug: debug) { ex. } end |
#log_redact(text, should_redact = nil) ⇒ String
67 68 69 70 71 72 73 |
# File 'lib/httpx/loggable.rb', line 67 def log_redact(text, should_redact = nil) should_redact ||= @options.debug_redact == true return text.to_s unless should_redact "[REDACTED]" end |
#log_redact_body(text) ⇒ String
63 64 65 |
# File 'lib/httpx/loggable.rb', line 63 def log_redact_body(text) log_redact(text, @options.debug_redact == :body) end |
#log_redact_headers(text) ⇒ String
59 60 61 |
# File 'lib/httpx/loggable.rb', line 59 def log_redact_headers(text) log_redact(text, @options.debug_redact == :headers) end |