Created
April 14, 2016 07:08
-
-
Save wkrsz/3dff0cbf8408bcd98ee122ac11cd9388 to your computer and use it in GitHub Desktop.
Log request details at Rack level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.middleware.use "Loggo" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
class Loggo | |
def initialize(app) | |
@app = app | |
# @log = File.open(Rails.root.join("log/loggo.log"), "a+") | |
@log = STDERR | |
end | |
def call(env) | |
headers = env.reject do |k,v| | |
k=~ /(rack|warden|action|honeybadger)/ | |
end | |
@log.write ">"*50 + "\n" | |
PP.pp(headers, @log) | |
@log.write "-"*50 + "\n" | |
response = @app.call(env) | |
@log.write response[0] | |
@log.write "\n" | |
@log.write response[1] | |
@log.write "\n" | |
@log.write response[2].try(:body) | |
@log.write "<"*50 + "\n" | |
@log.flush | |
response | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment