httplog 0.0.3

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Thilo Rusche
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = HttpLog
2
+
3
+ Log outgoing HTTP requests made from your application.
4
+
5
+ == Installation
6
+
7
+ Not yet on rubygems, so get if from here please.
8
+
9
+ == Usage
10
+
11
+ require 'httplog'
12
+
13
+ Yup, that's it. By default, this will log all Net::HTTP.request calls to $stdout on DEBUG level.
14
+
15
+ == Configuration
16
+
17
+ You can override the following default options:
18
+
19
+ HttpLog.options[:logger] = Logger.new($stdout)
20
+ HttpLog.options[:severity] = Logger::Severity::DEBUG
21
+ HttpLog.options[:log_connect] = true
22
+ HttpLog.options[:log_request] = true
23
+ HttpLog.options[:log_data] = true
24
+
25
+
26
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+ require 'rspec/core/rake_task'
15
+
16
+ desc "Run specs"
17
+ RSpec::Core::RakeTask.new(:spec)
18
+
19
+ desc "Generate documentation"
20
+ RDoc::Task.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'HttpLog'
23
+ rdoc.options << '--line-numbers' << '--inline-source'
24
+ rdoc.rdoc_files.include('README.rdoc')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+ # ----- Packaging -----
38
+ task :build do
39
+ sh "gem build httplog.gemspec"
40
+ mkdir_p 'pkg'
41
+ sh "mv *.gem pkg/ "
42
+ end
43
+
44
+ task :default => :spec
data/lib/httplog.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "httplog/version"
2
+ require "httplog/http_log"
@@ -0,0 +1,47 @@
1
+ require "net/http"
2
+ require "logger"
3
+
4
+ module HttpLog
5
+
6
+ def self.options
7
+ @@options ||= {
8
+ :logger => Logger.new($stdout),
9
+ :severity => Logger::Severity::DEBUG,
10
+ :log_connect => true,
11
+ :log_request => true,
12
+ :log_data => true
13
+ }
14
+ end
15
+
16
+ def self.log(msg)
17
+ @@options[:logger].add(@@options[:severity]) { msg }
18
+ end
19
+
20
+ end
21
+
22
+ module Net
23
+
24
+ class HTTP
25
+ alias_method(:orig_request, :request) unless method_defined?(:orig_request)
26
+ alias_method(:orig_connect, :connect) unless method_defined?(:orig_connect)
27
+
28
+ def request(req, body = nil, &block)
29
+
30
+ if HttpLog.options[:log_request]
31
+ HttpLog::log("Sending: #{req.method} http://#{@address}:#{@port}#{req.path}")
32
+ end
33
+
34
+ if req.request_body_permitted? && HttpLog.options[:log_data]
35
+ HttpLog::log("Data: #{req.body}")
36
+ end
37
+
38
+ orig_request(req, body, &block)
39
+ end
40
+
41
+ def connect
42
+ HttpLog::log("Connecting: #{@address}") if HttpLog.options[:log_connect]
43
+ orig_connect
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,3 @@
1
+ module HttpLog
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :httplog do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httplog
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.3
6
+ platform: ruby
7
+ authors:
8
+ - Thilo Rusche
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-18 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ description: |-
28
+ Log outgoing HTTP requests made from your application. Helpful for tracking API calls
29
+ of third party gems that don't provide their own log output.
30
+ email: thilorusche@gmail.com
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files: []
36
+
37
+ files:
38
+ - lib/httplog/http_log.rb
39
+ - lib/httplog/version.rb
40
+ - lib/httplog.rb
41
+ - lib/tasks/http_log_tasks.rake
42
+ - MIT-LICENSE
43
+ - Rakefile
44
+ - README.rdoc
45
+ has_rdoc: true
46
+ homepage: http://github.com/trusche/httplog
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 102058995
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.6.2
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Logs outgoing Net::HTTP requests.
76
+ test_files: []
77
+