Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ksylvest opened this issue Jun 21, 2024 · 0 comments

Comments

@ksylvest
Copy link

ksylvest commented Jun 21, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant