gpt4 book ai didi

ruby-on-rails - 在Rails应用中记录RestClient

转载 作者:行者123 更新时间:2023-12-04 13:20:30 25 4
gpt4 key购买 nike

我想用RestClient调试我的Rails应用程序发出的请求。 RestClient文档说:

To enable logging you can

set RestClient.log with a ruby Logger or set an environment variable to avoid modifying the code (in this case you can use a file name, “stdout” or “stderr”):

$ RESTCLIENT_LOG=stdout path/to/my/program Either produces logs like this:

RestClient.get "http://some/resource"

=> 200 OK | text/html 250 bytes

RestClient.put "http://some/resource", "payload"

=> 401 Unauthorized | application/xml 340 bytes

Note that these logs are valid Ruby, so you can paste them into the restclient shell or a >script to replay your sequence of rest calls.



如何将这些日志包含在我的Rails应用日志文件夹中?

最佳答案

来自:https://gist.github.com/jeremy/1383337

require 'restclient'

# RestClient logs using << which isn't supported by the Rails logger,
# so wrap it up with a little proxy object.
RestClient.log =
Object.new.tap do |proxy|
def proxy.<<(message)
Rails.logger.info message
end
end

关于ruby-on-rails - 在Rails应用中记录RestClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10068496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com