Skip to content

Instantly share code, notes, and snippets.

@DevGW
Created October 2, 2023 16:41
Show Gist options
  • Save DevGW/87d16a9aff5a63f7725e7cec2e7b42c1 to your computer and use it in GitHub Desktop.
Save DevGW/87d16a9aff5a63f7725e7cec2e7b42c1 to your computer and use it in GitHub Desktop.
Add middleware request logging for token testing to rails
#config/request_logger.rb
### NOTE: add the following two lines (uncommented) to your config/application.rb to load the middleware
# require_relative 'request_logger'
# config.middleware.use RequestLogger
class RequestLogger
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
Rails.logger.info("Headers: #{request.env.select { |k, _| k.start_with?('HTTP_') }}")
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment