How do I see the whole HTTP request in Rails

后端 未结 4 700
北海茫月
北海茫月 2020-12-29 04:20

I have a Rails application but after some time of development/debugging I realized that it would be very helpful to be able to see the whole HTTP request in the logfiles - l

4条回答
  •  囚心锁ツ
    2020-12-29 04:58

    That logger.info request.env code works fine in a Rails controller, but to see a more original version of that, or if you're using Grape or some other mounted app, you have to intercept the request on its way through the rack middleware chain...

    Put this code in your lib directory (or at the bottom of application.rb):

    require 'pp'
    class Loggo
      def initialize(app)
        @app = app
      end
      def call(env)
        pp env
        @app.call(env)
      end
    end
    

    then in with the other configs in application.rb:

    config.middleware.use "Loggo"
    

提交回复
热议问题