httplog 0.0.9 → 0.1.0
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.rdoc +18 -12
- data/lib/httplog/http_log.rb +9 -3
- data/lib/httplog/version.rb +1 -1
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
|
1
|
+
== httplog
|
2
2
|
|
3
3
|
Log outgoing HTTP requests made from your application.
|
4
4
|
|
5
|
-
|
5
|
+
=== Installation
|
6
6
|
|
7
7
|
gem install httplog
|
8
8
|
|
9
|
-
|
9
|
+
=== Usage
|
10
10
|
|
11
11
|
require 'httplog'
|
12
12
|
|
13
|
-
|
13
|
+
By default, this will log all outgoing HTTP requests and their responses to $stdout on DEBUG level.
|
14
14
|
|
15
|
-
|
15
|
+
=== Configuration
|
16
16
|
|
17
17
|
You can override the following default options:
|
18
18
|
|
@@ -20,22 +20,28 @@ You can override the following default options:
|
|
20
20
|
HttpLog.options[:severity] = Logger::Severity::DEBUG
|
21
21
|
HttpLog.options[:log_connect] = true
|
22
22
|
HttpLog.options[:log_request] = true
|
23
|
+
HttpLog.options[:log_headers] = false
|
23
24
|
HttpLog.options[:log_data] = true
|
24
25
|
HttpLog.options[:log_status] = true
|
25
26
|
HttpLog.options[:log_response] = true
|
26
27
|
HttpLog.options[:log_benchmark] = true
|
27
|
-
HttpLog.options[:compact_log] = false
|
28
|
+
HttpLog.options[:compact_log] = false = setting this to true will make all "log_*" options redundant
|
28
29
|
|
29
30
|
So if you want to use this in a Rails app:
|
30
31
|
|
31
|
-
|
32
|
+
= file: config/initializers/httplog.rb
|
32
33
|
|
33
34
|
HttpLog.options[:logger] = Rails.logger
|
34
35
|
|
35
|
-
|
36
|
+
=== Running the specs
|
36
37
|
|
37
|
-
|
38
|
-
run `bundle exec
|
39
|
-
|
38
|
+
Make sure you have the necessary dependencies installed by running `bundle install`.
|
39
|
+
Then simple run `bundle exec rspec spec`.
|
40
|
+
This will launch a simple rack server on port 9292 and run all tests locally against that server.
|
40
41
|
|
41
|
-
|
42
|
+
=== Contributing
|
43
|
+
|
44
|
+
If you have any issues with httplog,
|
45
|
+
or feature requests,
|
46
|
+
please [add an issue](https://github.com/trusche/httplog/issues) on GitHub
|
47
|
+
or fork the project and send a pull request.
|
data/lib/httplog/http_log.rb
CHANGED
@@ -36,6 +36,12 @@ module Net
|
|
36
36
|
HttpLog::log("[httplog] Sending: #{req.method} http://#{@address}:#{@port}#{req.path}")
|
37
37
|
end
|
38
38
|
|
39
|
+
if HttpLog.options[:log_headers]
|
40
|
+
req.each_header do |key,value|
|
41
|
+
HttpLog::log("[httplog] Header: #{key} -> #{value}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
39
45
|
if req.method == "POST" && HttpLog.options[:log_data]
|
40
46
|
# a bit convoluted becase post_form uses form_data= to assign the data, so
|
41
47
|
# in that case req.body will be empty
|
@@ -46,15 +52,15 @@ module Net
|
|
46
52
|
|
47
53
|
r0 = Time.now
|
48
54
|
response = orig_request(req, body, &block)
|
49
|
-
|
50
55
|
benchmark = Time.now - r0
|
56
|
+
|
51
57
|
if started?
|
52
58
|
if HttpLog.options[:compact_log]
|
53
59
|
HttpLog::log("[httplog] #{req.method} http://#{@address}:#{@port}#{req.path} completed with status code #{response.code} in #{benchmark}")
|
54
60
|
else
|
55
|
-
HttpLog::log("[httplog] Benchmark: #{benchmark}") if HttpLog.options[:log_benchmark]
|
56
61
|
HttpLog::log("[httplog] Status: #{response.code}") if HttpLog.options[:log_status]
|
57
|
-
HttpLog::log("[httplog] Response
|
62
|
+
HttpLog::log("[httplog] Response:\n#{response.body}") if HttpLog.options[:log_response]
|
63
|
+
HttpLog::log("[httplog] Benchmark: #{benchmark}") if HttpLog.options[:log_benchmark]
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
data/lib/httplog/version.rb
CHANGED
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.0
|
4
|
+
version: 0.1.0
|
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-10-
|
12
|
+
date: 2012-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -54,6 +54,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- - ! '>='
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
hash: 418187136863777166
|
57
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
61
|
none: false
|
59
62
|
requirements:
|
@@ -67,4 +70,3 @@ signing_key:
|
|
67
70
|
specification_version: 3
|
68
71
|
summary: Logs outgoing Net::HTTP requests.
|
69
72
|
test_files: []
|
70
|
-
has_rdoc:
|