httplog 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,18 +1,18 @@
1
- = httplog
1
+ == httplog
2
2
 
3
3
  Log outgoing HTTP requests made from your application.
4
4
 
5
- == Installation
5
+ === Installation
6
6
 
7
7
  gem install httplog
8
8
 
9
- == Usage
9
+ === Usage
10
10
 
11
11
  require 'httplog'
12
12
 
13
- Yup, that's it. By default, this will log all outgoing HTTP requests and their responses to $stdout on DEBUG level.
13
+ By default, this will log all outgoing HTTP requests and their responses to $stdout on DEBUG level.
14
14
 
15
- == Configuration
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 # setting this to true will make all "log_*" options redundant
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
- # file: config/initializers/httplog.rb
32
+ = file: config/initializers/httplog.rb
32
33
 
33
34
  HttpLog.options[:logger] = Rails.logger
34
35
 
35
- == Development
36
+ === Running the specs
36
37
 
37
- To run the tests, a web server must be listening on localhost port 3000. Then simply
38
- run `bundle exec rake`. The tests will make GET and POST requests to `http://localhost:3000/foo` by
39
- default.
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
- TODO: Make tests self-contained.
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.
@@ -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: #{response.body}") if HttpLog.options[:log_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
 
@@ -1,3 +1,3 @@
1
1
  module HttpLog
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
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.9
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-01 00:00:00.000000000 Z
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: