Class: HTTP::Features::Logging::BodyLogger
- Inherits:
-
Object
- Object
- HTTP::Features::Logging::BodyLogger
- Defined in:
- lib/http/features/logging.rb
Overview
Stream wrapper that logs each chunk as it flows through readpartial
Instance Attribute Summary collapse
-
#connection ⇒ HTTP::Connection
readonly
The underlying connection.
Instance Method Summary collapse
-
#initialize(stream, logger, formatter: nil) ⇒ BodyLogger
constructor
Create a new BodyLogger wrapping a stream.
-
#readpartial ⇒ String
Read a chunk from the underlying stream and log it.
Constructor Details
#initialize(stream, logger, formatter: nil) ⇒ BodyLogger
Create a new BodyLogger wrapping a stream
208 209 210 211 212 213 |
# File 'lib/http/features/logging.rb', line 208 def initialize(stream, logger, formatter: nil) @stream = stream @connection = stream.respond_to?(:connection) ? stream.connection : stream @logger = logger @formatter = formatter end |
Instance Attribute Details
#connection ⇒ HTTP::Connection (readonly)
The underlying connection
196 197 198 |
# File 'lib/http/features/logging.rb', line 196 def connection @connection end |
Instance Method Details
#readpartial ⇒ String
Read a chunk from the underlying stream and log it
223 224 225 226 227 |
# File 'lib/http/features/logging.rb', line 223 def readpartial(*) chunk = @stream.readpartial(*) @logger.debug { @formatter ? @formatter.call(chunk) : chunk } # steep:ignore chunk end |