Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging RestClient in a Rails app

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?

like image 314
user94154 Avatar asked Apr 09 '12 03:04

user94154


People also ask

What is a rails Debug log?

By default, Rails applications generate logs at the debug level for all environments, including production. A single debug log entry can carry a lot of information: Since this log level includes the most diagnostic information related to your application, it’s valuable for development or test environments.

How to add custom logging for rails?

Even in their default format, Rails logs provide information that can be very helpful in troubleshooting common application errors. To collect a greater amount of detail, you can add custom logging for Rails. To further enhance the logs your application generates, you can create customized logs with the ActiveSupport::Logger class.

What is the default log level in rails?

The default Rails log level is info in production mode and debug in development and test modes. For the application, we are going to use the default Logger class. The logger will have a log/all.log file as the logging target and info as the minimum log level.

How well does rails manage logs?

In small applications, Rails manages logs well, so you can easily debug issues without the need for third-party libraries. As your application grows, however, you will need to consider how to better manage the volume of logs it generates.


2 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
like image 80
nessur Avatar answered Oct 12 '22 23:10

nessur


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

like image 43
Dzmitry Avatar answered Oct 12 '22 23:10

Dzmitry