This is a quick one, but if your Rails app uses ActiveResource as a client, it can be really useful to know something about each ARes request.
ActiveResource actually has some built-in logging of what requests are made, the response size, and how long it took. But, it’s not enabled. The good news is, it’s easy to turn it on.
I like to make ActiveResource’s logging match the rest of my environment — that is, it will log when in development mode and not in production mode.
Add the following to a file in
1ActiveResource::Base.logger = ActionController::Base.logger
Obviously, if you want it to go to a different log file, or function at a different log level, you can create a new Logger instance instead.
The logging output will look something like this:
tags: rails, activeresource, logging
1GET http://api-server.com/resources.xml 2--> 200 OK (1526 69ms)