Bogdan Gusiev's blog

How to make good software for people


Logging HTTP api calls just like database queries
24 May 2011

Http api calls are pretty similar to SQL queries - they query data from external source to process them in ruby space. So I think it's a good idea to log them just like ActiveRecord does with SQL queries.
  Location Load (25.1ms)   SELECT * FROM "locations" WHERE ("locations"."id" = 2548) ORDER BY title
This simple peace of code could be very helpful in case of debugging HTTP api in ruby. Screenshot with the result Installation is simple:
gem install http_logger
And:
require 'http_logger'

Net::HTTP.logger = Logger.new(...) 
    # Default: Rails.logger if defined?(Rails)

Net::HTTP.colorize = true 
    # Default: true

api http logging ruby rails debug gem