httplog 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -4,11 +4,19 @@ Log outgoing HTTP requests made from your application.
4
4
  See the [blog post](http://trusche.github.com/blog/2011/09/29/logging-outgoing-http-requests/)
5
5
  for more details.
6
6
 
7
- So far this gem works with the following HTTP libraries:
7
+ So far this gem works with the following ruby modules and libraries:
8
8
 
9
- * Net::HTTP
10
- * OpenURI
11
- * HTTPClient
9
+ * [Net::HTTP](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/index.html)
10
+ * [Ethon](https://github.com/typhoeus/ethon)
11
+ * [Excon](https://github.com/geemus/excon)
12
+ * [OpenURI](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/index.html)
13
+ * [HTTPClient](https://github.com/nahi/httpclient)
14
+ * [HTTParty](https://github.com/jnunemaker/httparty)
15
+
16
+ These libraries are at least partially supported, where they use one of the above as adapters:
17
+
18
+ * [Faraday](https://github.com/technoweenie/faraday)
19
+ * [Typhoeus](https://github.com/typhoeus/typhoeus)
12
20
 
13
21
  In theory, it should also work with any library built on top of these. But since
14
22
  the difference between theory and practice is bigger in practice than in theory, YMMV.
@@ -50,7 +58,7 @@ So if you want to use this in a Rails app:
50
58
 
51
59
  With the default configuration, the log output might look like this:
52
60
 
53
- D, [2012-11-21T15:09:03.532970 #6857] DEBUG -- : [httplog] Connecting: localhost
61
+ D, [2012-11-21T15:09:03.532970 #6857] DEBUG -- : [httplog] Connecting: localhost:80
54
62
  D, [2012-11-21T15:09:03.533877 #6857] DEBUG -- : [httplog] Sending: GET http://localhost:9292/index.html
55
63
  D, [2012-11-21T15:09:03.534499 #6857] DEBUG -- : [httplog] Status: 200
56
64
  D, [2012-11-21T15:09:03.534544 #6857] DEBUG -- : [httplog] Benchmark: 0.00057 seconds
@@ -67,10 +75,14 @@ With the default configuration, the log output might look like this:
67
75
 
68
76
  ### Known Issues
69
77
 
78
+ * Requests types other than GET and POST have not been explicitly tested.
79
+ They may or may not be logged, depending on the implementation details of the underlying library.
80
+ If they are not for a particular library, please feel free to open an issue with the details.
81
+
70
82
  * When using OpenURI, the reading of the HTTP response body is deferred,
71
83
  so it is not available for logging. This will be noted in the logging statement:
72
84
 
73
- D, [2012-11-21T15:09:03.547005 #6857] DEBUG -- : [httplog] Connecting: localhost
85
+ D, [2012-11-21T15:09:03.547005 #6857] DEBUG -- : [httplog] Connecting: localhost:80
74
86
  D, [2012-11-21T15:09:03.547938 #6857] DEBUG -- : [httplog] Sending: GET http://localhost:9292/index.html
75
87
  D, [2012-11-21T15:09:03.548615 #6857] DEBUG -- : [httplog] Status: 200
76
88
  D, [2012-11-21T15:09:03.548662 #6857] DEBUG -- : [httplog] Benchmark: 0.000617 seconds
@@ -79,6 +91,16 @@ With the default configuration, the log output might look like this:
79
91
  * When using HTTPClient, the TCP connection establishment will be logged
80
92
  *after* the HTTP request and headers, due to the way HTTPClient is organized.
81
93
 
94
+ D, [2012-11-22T18:39:46.031698 #12800] DEBUG -- : [httplog] Sending: GET http://localhost:9292/index.html
95
+ D, [2012-11-22T18:39:46.031756 #12800] DEBUG -- : [httplog] Header: accept: */*
96
+ D, [2012-11-22T18:39:46.031788 #12800] DEBUG -- : [httplog] Header: foo: bar
97
+ D, [2012-11-22T18:39:46.031942 #12800] DEBUG -- : [httplog] Connecting: localhost:9292
98
+ D, [2012-11-22T18:39:46.033409 #12800] DEBUG -- : [httplog] Status: 200
99
+ D, [2012-11-22T18:39:46.033483 #12800] DEBUG -- : [httplog] Benchmark: 0.001562 seconds
100
+
101
+ * When using Ethon and any library based on it (such as Typhoeus),
102
+ the TCP connection is not logged (since it's established by libcurl).
103
+
82
104
  ### Running the specs
83
105
 
84
106
  Make sure you have the necessary dependencies installed by running `bundle install`.
data/lib/httplog.rb CHANGED
@@ -2,3 +2,5 @@ require "httplog/version"
2
2
  require "httplog/http_log"
3
3
  require "httplog/adapters/net_http"
4
4
  require "httplog/adapters/httpclient"
5
+ require "httplog/adapters/excon"
6
+ require "httplog/adapters/ethon"
@@ -0,0 +1,36 @@
1
+ if defined?(Ethon)
2
+ module Ethon
3
+ class Easy
4
+
5
+ module Http
6
+ alias_method :orig_http_request, :http_request
7
+ def http_request(url, action_name, options = {})
8
+ HttpLog.log_request(action_name, url)
9
+ HttpLog.log_headers(options[:headers])
10
+ HttpLog.log_data(options[:body]) if action_name == :post
11
+
12
+ orig_http_request(url, action_name, options)
13
+ end
14
+ end
15
+
16
+ module Operations
17
+ alias_method :orig_perform, :perform
18
+ def perform
19
+ response_code = nil
20
+ bm = Benchmark.realtime do
21
+ reponse_code = orig_perform
22
+ end
23
+
24
+ # Not sure where the acutal status code is stored - so let's
25
+ # extract it from the response header.
26
+ status = response_headers.scan(/HTTP\/... (\d{3})/).flatten.first
27
+ HttpLog.log_compact(@action_name, @url, @return_code, bm)
28
+ HttpLog.log_status(status)
29
+ HttpLog.log_benchmark(bm)
30
+ HttpLog.log_body(response_body)
31
+ return_code
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ if defined?(Excon)
2
+ module Excon
3
+ class Socket
4
+ alias_method :orig_connect, :connect
5
+ def connect
6
+ host = @proxy ? @proxy[:host] : @params[:host]
7
+ port = @proxy ? @proxy[:port] : @params[:port]
8
+ HttpLog.log_connection(host, port)
9
+ orig_connect
10
+ end
11
+
12
+ end
13
+
14
+ class Connection
15
+ alias_method :orig_request_kernel, :request_kernel
16
+ def request_kernel(params)
17
+ url = "#{params[:scheme]}://#{params[:host]}:#{params[:port]}#{params[:path]}#{params[:query]}"
18
+ HttpLog.log_request(params[:method], url)
19
+ HttpLog.log_headers(params[:headers])
20
+ HttpLog.log_data(params[:body]) if params[:method] == :post
21
+
22
+ response = nil
23
+ bm = Benchmark.realtime do
24
+ response = orig_request_kernel(params)
25
+ end
26
+
27
+ HttpLog.log_compact(params[:method], url, response.status, bm)
28
+ HttpLog.log_status(response.status)
29
+ HttpLog.log_benchmark(bm)
30
+ HttpLog.log_body(response.body)
31
+
32
+ response
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  if defined?(::HTTPClient)
3
2
  class HTTPClient
4
3
  private
@@ -1,4 +1,4 @@
1
1
  module HttpLog
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httplog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-22 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -75,6 +75,86 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: httparty
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: faraday
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: excon
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: typhoeus
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: ethon
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
78
158
  description: ! "Log outgoing HTTP requests made from your application. Helpful for
79
159
  tracking API calls\n of third party gems that don't provide
80
160
  their own log output."
@@ -83,6 +163,8 @@ executables: []
83
163
  extensions: []
84
164
  extra_rdoc_files: []
85
165
  files:
166
+ - lib/httplog/adapters/ethon.rb
167
+ - lib/httplog/adapters/excon.rb
86
168
  - lib/httplog/adapters/httpclient.rb
87
169
  - lib/httplog/adapters/net_http.rb
88
170
  - lib/httplog/http_log.rb
@@ -114,5 +196,6 @@ rubyforge_project:
114
196
  rubygems_version: 1.8.24
115
197
  signing_key:
116
198
  specification_version: 3
117
- summary: Logs outgoing Net::HTTP requests.
199
+ summary: Logs outgoing HTTP requests.
118
200
  test_files: []
201
+ has_rdoc: