Skip to content

Feature Request: Better Control of Logging for Binary Request Body / Response Body #784

@ksylvest

Description

@ksylvest

For non-textual files any logger running w/ an INFO level causes a lot of noise / gibberish. For example, with logging and an AAC file:

11:55:13 | ??X@??libfaac 1.30?;~,?2Sx??2֡?"dI$D??:L??tY}?q????T?J?9�R?~???W?Md?????/?????????~
...

It doesn't appear to be possible to customize this outside changing the log level to never see request.body / response.body. For example:

wrap_response

Current:

logger.info { "< #{response.status}" }
logger.debug { "#{stringify_headers(response.headers)}\n\n#{response.body}" }

Proposed:

logger.info { "< #{response.status}" }
logger.debug { "#{stringify_headers(response.headers)}" }
if response.body.log?
  logger.debug { "\n\n" }
  logger.debug { String(response.body) } 
end

log? might be:

def log?
  @encoding != Encoding::BINARY
end

wrap_request

Current:

logger.info { "> #{request.verb.to_s.upcase} #{request.uri}" }
logger.debug { "#{stringify_headers(request.headers)}\n\n#{request.body.source}" }

Proposed:

logger.info { "> #{request.verb.to_s.upcase} #{request.uri}" }
logger.debug { "#{stringify_headers(request.headers)}" }
if request.body.log?
  logger.debug { "\n\n" }
  logger.debug { String(response.body) } 
end

log? might be:

def log?
  @source.is_a?(String)
end

If this is something of interest I'd be happy to look into further.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions