我如何在Rails中看到整个HTTP请求 [英] How do I see the whole HTTP request in Rails
问题描述
我有一个Rails应用程序,但是经过一段时间的开发/调试后,我意识到能够在日志文件中看到整个HTTP请求非常有用-log/development.log,而不仅仅是参数.
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 - log/development.log, not just the parameters.
我还希望有一个基于用户而不是会话的单独的日志文件.
I also want to have a separate logfile based on user, not session.
任何想法都会受到赞赏!
Any ideas will be appreciated!
推荐答案
您可以通过以下方式在视图中快速查看request.env:
You can rapidly see the request.env in a view via:
- 查看:<%= request.env.inspect%>
- VIEW: <%= request.env.inspect %>
如果您想将其记录在开发日志中,请从您的控制器中进行
If instead you want to log it in development log, from your controller:
- 控制器:Rails.logger.info(request.env)
- CONTROLLER: Rails.logger.info(request.env)
在这里您可以看到Request对象的参考.
Here you can see a reference for the Request object.
Rails使用Ruby Standard Library中的Logger自动将日志记录设置为log/目录中的文件.日志文件将根据您的环境进行命名,例如日志/development.log.
Rails automatically sets up logging to a file in the log/ directory using Logger from the Ruby Standard Library. The logfile will be named corresponding to your environment, e.g. log/development.log.
要从控制器或模型记录消息,请使用logger方法访问Rails记录器实例:
To log a message from either a controller or a model, access the Rails logger instance with the logger method:
class YourController < ActionController::Base
def index
logger.info request.env
end
end
关于用户,您使用什么对其进行身份验证?
About the user, what are you using to authenticate It?
这篇关于我如何在Rails中看到整个HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!