Skip to content

Instantly share code, notes, and snippets.

@alfie-max
Created December 21, 2016 08:41
Show Gist options
  • Save alfie-max/730dfcfa582b1965c3cf8ed58e63b700 to your computer and use it in GitHub Desktop.
Save alfie-max/730dfcfa582b1965c3cf8ed58e63b700 to your computer and use it in GitHub Desktop.
config.log_level = :debug
config.middleware.use LogPrettyJson
class LogPrettyJson
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
if defined?(Rails) && headers["Content-Type"] =~ /^application\/json/
obj = JSON.parse(response.body)
pretty_str = JSON.pretty_unparse(obj)
Rails.logger.debug("Response: " + pretty_str)
end
[status, headers, response]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment