RestClient logging in a Rails application

I would like to debug a request that a Rails application makes using RestClient . RestClient docs say:

To enable logging, you can

set RestClient.log using a ruby ​​logger or set an environment variable to avoid changing the code (in this case you can use the file name, "stdout" or "stderr"):

$ RESTCLIENT_LOG = path stdout / to / my / program Either logs are created:

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 a restclient or> script to reproduce a sequence of calls to rest.

How do I get these logs included in the Rails application log folder?

+6
source share
4 answers

from: 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 
+13
source

Create a file in config/initializers :
RestClient.log = 'log / a_log_file.log'
Or just put the latter in the console

https://github.com/adelevie/rest-client/commit/5a7ed325eaa091809141d3ef6e31087569614e9d

+4
source

You can use this gem:

https://github.com/uswitch/rest-client-logger

This works out of the box by simply adding "gem" rest-client-logger "to your Gemfile.

+1
source

could be like this: RestClient.log = Rails.logger

-3
source

Source: https://habr.com/ru/post/912718/


All Articles