http_logger 0.0.1
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +49 -0
- data/Readme.md +26 -0
- data/VERSION +1 -0
- data/http_logger.gemspec +62 -0
- data/lib/http_logger.rb +75 -0
- data/screenshots/hoptoad.png +0 -0
- data/screenshots/rails_console.png +0 -0
- data/spec/http_logger_spec.rb +11 -0
- data/spec/spec_helper.rb +19 -0
- metadata +141 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.0)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.6.0)
|
27
|
+
rcov
|
28
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Bogdan Gusiev
|
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/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "http_logger"
|
18
|
+
gem.homepage = "http://github.com/bogdan/http_logger"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Log your http api calls just like SQL queries}
|
21
|
+
gem.description = %Q{This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file}
|
22
|
+
gem.email = "agresso@gmail.com"
|
23
|
+
gem.authors = ["Bogdan Gusiev"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "http_logger #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Net::HTTP logger
|
2
|
+
|
3
|
+
Simple gem that logs your HTTP api requests just like database queries
|
4
|
+
|
5
|
+
|
6
|
+
## Screenshot
|
7
|
+
|
8
|
+
* [Hoptoad](https://github.com/railsware/http_logger/raw/master/screenshots/hoptoad.png)
|
9
|
+
* [Google](https://github.com/railsware/http_logger/raw/master/screenshots/rails_console.png)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
gem install http_logger
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
require 'http_logger'
|
18
|
+
|
19
|
+
Net::HTTP.logger = Logger.new(...) # defaults to Rails.logger if Rails is defined
|
20
|
+
Net::HTTP.colorize = true # Default: true
|
21
|
+
|
22
|
+
|
23
|
+
## Alternative
|
24
|
+
|
25
|
+
Net::HTTP has a builtin logger that can be set via \#set\_debug\_output.
|
26
|
+
This method is only available at the instance level and it is not always accessible if used inside of a library. Also output of builtin debugger is not formed well for API debug purposes.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/http_logger.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{http_logger}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bogdan Gusiev"]
|
12
|
+
s.date = %q{2011-05-07}
|
13
|
+
s.description = %q{This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file}
|
14
|
+
s.email = %q{agresso@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"Rakefile",
|
25
|
+
"Readme.md",
|
26
|
+
"VERSION",
|
27
|
+
"http_logger.gemspec",
|
28
|
+
"lib/http_logger.rb",
|
29
|
+
"screenshots/hoptoad.png",
|
30
|
+
"screenshots/rails_console.png",
|
31
|
+
"spec/http_logger_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/bogdan/http_logger}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Log your http api calls just like SQL queries}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
48
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
53
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/http_logger.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
# Usage:
|
4
|
+
#
|
5
|
+
# require 'http_logger'
|
6
|
+
#
|
7
|
+
# == Setup logger
|
8
|
+
#
|
9
|
+
# Net::HTTP.logger = Logger.new('/tmp/all.log')
|
10
|
+
#
|
11
|
+
# == Do request
|
12
|
+
#
|
13
|
+
# res = Net::HTTP.start(url.host, url.port) { |http|
|
14
|
+
# http.request(req)
|
15
|
+
# }
|
16
|
+
# ...
|
17
|
+
|
18
|
+
class Net::HTTP
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :logger
|
22
|
+
attr_accessor :colorize
|
23
|
+
end
|
24
|
+
|
25
|
+
self.colorize = true
|
26
|
+
|
27
|
+
|
28
|
+
alias_method :request_without_logging, :request
|
29
|
+
|
30
|
+
def request(request, body = nil, &block)
|
31
|
+
time = Time.now
|
32
|
+
response = request_without_logging(request, body, &block)
|
33
|
+
response
|
34
|
+
ensure
|
35
|
+
if self.started? && self.logger
|
36
|
+
url = "http#{"s" if self.use_ssl?}://#{self.address}:#{self.port}#{request.path}"
|
37
|
+
ofset = Time.now - time
|
38
|
+
log("HTTP #{request.method} (%0.2fms)" % (ofset * 1000), url)
|
39
|
+
log("POST params", request.body) if request.is_a?(::Net::HTTP::Post)
|
40
|
+
if defined?(response) && response
|
41
|
+
log("Response status", "#{response.class} (#{response.code})")
|
42
|
+
body = response.body
|
43
|
+
log("Response body", body) unless body.is_a?(Net::ReadAdapter)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
def log(message, dump)
|
50
|
+
self.logger.debug(format_log_entry(message, dump))
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_log_entry(message, dump = nil)
|
54
|
+
if self.class.colorize
|
55
|
+
message_color, dump_color = "4;32;1", "0;1"
|
56
|
+
log_entry = " \e[#{message_color}m#{message}\e[0m "
|
57
|
+
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
|
58
|
+
log_entry
|
59
|
+
else
|
60
|
+
"%s %s" % [message, dump]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def logger
|
65
|
+
self.class.logger
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
if defined?(Rails)
|
72
|
+
Net::HTTP.logger = Rails.logger
|
73
|
+
end
|
74
|
+
|
75
|
+
|
Binary file
|
Binary file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HttpLogger" do
|
4
|
+
it "should log request" do
|
5
|
+
uri = URI.parse("http://google.com/")
|
6
|
+
|
7
|
+
response = Net::HTTP.get_response(uri)
|
8
|
+
File.read(LOGFILE).should_not be_empty
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'http_logger'
|
5
|
+
require "logger"
|
6
|
+
require "fileutils"
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
LOGFILE = 'http.log'
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
|
16
|
+
FileUtils.rm_f(LOGFILE)
|
17
|
+
Net::HTTP.logger = Logger.new(LOGFILE)
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Bogdan Gusiev
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-07 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 0
|
35
|
+
version: 2.3.0
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 23
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: jeweler
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 15
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 6
|
66
|
+
- 0
|
67
|
+
version: 1.6.0
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcov
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirement: *id004
|
83
|
+
description: This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file
|
84
|
+
email: agresso@gmail.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE.txt
|
91
|
+
files:
|
92
|
+
- .document
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- Rakefile
|
98
|
+
- Readme.md
|
99
|
+
- VERSION
|
100
|
+
- http_logger.gemspec
|
101
|
+
- lib/http_logger.rb
|
102
|
+
- screenshots/hoptoad.png
|
103
|
+
- screenshots/rails_console.png
|
104
|
+
- spec/http_logger_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
has_rdoc: true
|
107
|
+
homepage: http://github.com/bogdan/http_logger
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.3.7
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Log your http api calls just like SQL queries
|
140
|
+
test_files: []
|
141
|
+
|