Logging RestClient in a Rails app
Asked Answered
B

5

6

I'd like to debug the request my Rails app makes with RestClient. The RestClient docs say:

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.

How do I do get these logs included in my Rails apps log folder?

Balcke answered 9/4, 2012 at 3:10 Comment(0)
P
15

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
Pericline answered 21/2, 2013 at 15:50 Comment(2)
OR RestClient.log = $stdoutOrnithopod
Add that into a file in config/initializers/Steelman
T
5

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

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

Trovillion answered 21/6, 2012 at 5:3 Comment(0)
D
1

This worked for me, running on RestClient 1.8 and Rails 4.2.1:

::RestClient.log = Rails.logger

Damiondamita answered 22/8, 2018 at 18:48 Comment(1)
that can be added into config/initializers/rest_client.rb to globally enableMongolia
C
0

You can use this gem:

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

It works out of the box just by adding "gem 'rest-client-logger'" to your Gemfile.

Cirrhosis answered 25/11, 2015 at 3:56 Comment(0)
P
-3

may be so: RestClient.log = Rails.logger

Puzzlement answered 11/4, 2012 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.