## httplog [![Gem Version](https://badge.fury.io/rb/httplog.png)](http://badge.fury.io/rb/httplog) [![Build Status](https://travis-ci.org/trusche/httplog.svg?branch=master)](https://travis-ci.org/trusche/httplog) [![Code Climate](https://codeclimate.com/github/trusche/httplog.png)](https://codeclimate.com/github/trusche/httplog) Log outgoing HTTP requests made from your application. See the [blog post](http://trusche.github.com/blog/2011/09/29/logging-outgoing-http-requests/) for more details. So far this gem works with the following ruby modules and libraries: * [Net::HTTP](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/index.html) * [Ethon](https://github.com/typhoeus/ethon) (**Needs work to support latest versions**) * [Excon](https://github.com/geemus/excon) (for excon >= v18.0, httplog >= 0.2.4 is required) * [OpenURI](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/index.html) * [Patron](https://github.com/toland/patron) * [HTTPClient](https://github.com/nahi/httpclient) * [HTTParty](https://github.com/jnunemaker/httparty) * [HTTP](https://github.com/httprb/http) These libraries are at least partially supported, where they use one of the above as adapters: * [Faraday](https://github.com/technoweenie/faraday) * [Typhoeus](https://github.com/typhoeus/typhoeus) (**Needs work to support latest versions**) In theory, it should also work with any library built on top of these. But since the difference between theory and practice is bigger in practice than in theory, YMMV. This is very much a development and debugging tool; it is **not recommended** to use this in a production environment. ### Installation gem install httplog ### Usage require 'httplog' # require this *after* your HTTP gem of choice By default, this will log all outgoing HTTP requests and their responses to $stdout on DEBUG level. ### Notes on content types * Binary data from response bodies (as indicated by the `Content-Type` header)is not logged. * Text data (`text/*` and most `application/*` types) is encoded as UTF-8, with invalid characters replaced. If you need to inspect raw non-UTF data exactly as sent over the wire, this tool is probably not for you. ### Configuration You can override the following default options: HttpLog.options[:logger] = Logger.new($stdout) HttpLog.options[:severity] = Logger::Severity::DEBUG HttpLog.options[:log_connect] = true HttpLog.options[:log_request] = true HttpLog.options[:log_headers] = false HttpLog.options[:log_data] = true HttpLog.options[:log_status] = true HttpLog.options[:log_response] = true HttpLog.options[:log_benchmark] = true HttpLog.options[:compact_log] = false # setting this to true will make all "log_*" options redundant HttpLog.options[:color] = false # (see below) # only log requests made to specified hosts (URLs) HttpLog.options[:url_whitelist_pattern] = /.*/ # overrides whitelist HttpLog.options[:url_blacklist_pattern] = nil So if you want to use this in a Rails app: # config/initializers/httplog.rb HttpLog.options[:logger] = Rails.logger You can colorize the output to make it stand out in your logfile: HttpLog.options[:color] = {color: :black, background: :light_red} For more color options see [colorize documentation](https://github.com/fazibear/colorize/blob/master/README.md) ### Compact logging If the log is too noisy for you, but you don't want to completely disable it either, set the `compact_log` option to `true`. This will log each request in a single line with method, request URI, response status and time, but no data or headers. No need to disable any other options individually. ### Example With the default configuration, the log output might look like this: D, [2012-11-21T15:09:03.532970 #6857] DEBUG -- : [httplog] Connecting: localhost:80 D, [2012-11-21T15:09:03.533877 #6857] DEBUG -- : [httplog] Sending: GET http://localhost:9292/index.html D, [2012-11-21T15:09:03.534499 #6857] DEBUG -- : [httplog] Status: 200 D, [2012-11-21T15:09:03.534544 #6857] DEBUG -- : [httplog] Benchmark: 0.00057 seconds D, [2012-11-21T15:09:03.534578 #6857] DEBUG -- : [httplog] Response: