samuel 0.2.0 → 0.2.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/README.rdoc +15 -7
- data/VERSION +1 -1
- data/lib/samuel.rb +2 -2
- data/lib/samuel/request.rb +8 -2
- data/samuel.gemspec +2 -2
- data/test/request_test.rb +23 -8
- data/test/samuel_test.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ If you don't assign a logger, Samuel will configure a default logger on +STDOUT+
|
|
29
29
|
There are two ways to specify configuration options for Samuel: global and
|
30
30
|
inline. Global configs look like this:
|
31
31
|
|
32
|
-
Samuel.config[:
|
32
|
+
Samuel.config[:labels] = {"example.com" => "Example API"}
|
33
33
|
Samuel.config[:filtered_params] = :password
|
34
34
|
|
35
35
|
You should put global configuration somewhere early-on in your program. If
|
@@ -42,12 +42,20 @@ configuration for a set of HTTP requests:
|
|
42
42
|
Net::HTTP.start("twitter.com") { |http| http.get("/help/test") }
|
43
43
|
end
|
44
44
|
|
45
|
-
Right now, there are
|
46
|
-
|
47
|
-
* +:
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
Right now, there are three configuration changes you can make in either style:
|
46
|
+
|
47
|
+
* +:labels+ - This is a hash with domain substrings as keys and log labels as
|
48
|
+
values. If a request domain includes one of the domain substrings, the
|
49
|
+
corresponding label will be used for the first part of that log entry. By
|
50
|
+
default this is set to <tt>\{"" => "HTTP"}</tt>, so that all requests are
|
51
|
+
labeled with <tt>"HTTP Request"</tt>.
|
52
|
+
* +:label+ - As an alternative to the +:labels+ hash, this is simply a string.
|
53
|
+
If set, it takes precedence over any +:labels+ (by default, it's not set). It
|
54
|
+
gets <tt>"Request"</tt> appended to it as well -- so if you want your log to
|
55
|
+
always say +Twitter API Request+ instead of the default +HTTP Request+, you
|
56
|
+
can set this to <tt>"Twitter API"</tt>. I'd recommend using this setting
|
57
|
+
globally if you're only making requests to one service, or inline if you just
|
58
|
+
need to temporarily override the global +:labels+.
|
51
59
|
* +:filtered_params+ - This works just like Rails's +filter_parameter_logging+
|
52
60
|
method. Set it to a symbol, string, or array of them, and Samuel will filter
|
53
61
|
the value of query parameters that have any of these patterns as a substring
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/samuel.rb
CHANGED
@@ -29,7 +29,7 @@ module Samuel
|
|
29
29
|
|
30
30
|
def log_request(http, request, &block)
|
31
31
|
request = Request.new(http, request, block)
|
32
|
-
request.
|
32
|
+
request.perform_and_log!
|
33
33
|
request.response
|
34
34
|
end
|
35
35
|
|
@@ -44,7 +44,7 @@ module Samuel
|
|
44
44
|
|
45
45
|
def reset_config
|
46
46
|
Thread.current[:__samuel_config] = nil
|
47
|
-
@config = {:label => "HTTP", :filtered_params => []}
|
47
|
+
@config = {:label => nil, :labels => {"" => "HTTP"}, :filtered_params => []}
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
data/lib/samuel/request.rb
CHANGED
@@ -7,7 +7,7 @@ module Samuel
|
|
7
7
|
@http, @request, @proc = http, request, proc
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def perform_and_log!
|
11
11
|
# If an exception is raised in the Benchmark block, it'll interrupt the
|
12
12
|
# benchmark. Instead, use an inner block to record it as the "response"
|
13
13
|
# for raising after the benchmark (and logging) is done.
|
@@ -25,7 +25,6 @@ module Samuel
|
|
25
25
|
blue = "\e[34m"
|
26
26
|
underline = "\e[4m"
|
27
27
|
reset = "\e[0m"
|
28
|
-
label = Samuel.config[:label]
|
29
28
|
" #{bold}#{blue}#{underline}#{label} request (#{milliseconds}ms) " +
|
30
29
|
"#{response_summary}#{reset} #{method} #{uri}"
|
31
30
|
end
|
@@ -69,6 +68,13 @@ module Samuel
|
|
69
68
|
@request.method.to_s.upcase
|
70
69
|
end
|
71
70
|
|
71
|
+
def label
|
72
|
+
return Samuel.config[:label] if Samuel.config[:label]
|
73
|
+
|
74
|
+
pair = Samuel.config[:labels].detect { |domain, label| @http.address.include?(domain) }
|
75
|
+
pair[1] if pair
|
76
|
+
end
|
77
|
+
|
72
78
|
def response_summary
|
73
79
|
if response.is_a?(Exception)
|
74
80
|
response.class
|
data/samuel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{samuel}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Kampmeier"]
|
12
|
-
s.date = %q{2009-09-
|
12
|
+
s.date = %q{2009-09-15}
|
13
13
|
s.description = %q{An automatic logger for HTTP requests in Ruby. Adds Net::HTTP request logging to your Rails logs, and more.}
|
14
14
|
s.email = %q{chris@kampers.net}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/request_test.rb
CHANGED
@@ -96,7 +96,8 @@ class RequestTest < Test::Unit::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
should_log_including "Example request"
|
99
|
-
should_have_config_afterwards_including :
|
99
|
+
should_have_config_afterwards_including :labels => {"" => "HTTP"},
|
100
|
+
:label => nil
|
100
101
|
end
|
101
102
|
|
102
103
|
context "inside a configuration block with :filter_params" do
|
@@ -111,7 +112,7 @@ class RequestTest < Test::Unit::TestCase
|
|
111
112
|
should_log_including "http://example.com/test?password=[FILTERED]&username=chrisk"
|
112
113
|
end
|
113
114
|
|
114
|
-
context "=> :
|
115
|
+
context "=> :as" do
|
115
116
|
setup { Samuel.with_config(:filtered_params => :ass) { open @uri } }
|
116
117
|
should_log_including "http://example.com/test?password=[FILTERED]&username=chrisk"
|
117
118
|
end
|
@@ -130,7 +131,8 @@ class RequestTest < Test::Unit::TestCase
|
|
130
131
|
end
|
131
132
|
|
132
133
|
should_log_including "Example request"
|
133
|
-
should_have_config_afterwards_including :
|
134
|
+
should_have_config_afterwards_including :labels => {"" => "HTTP"},
|
135
|
+
:label => "Example"
|
134
136
|
end
|
135
137
|
|
136
138
|
context "with a global config including :label => 'Example' but inside config block that changes it to 'Example 2'" do
|
@@ -141,7 +143,8 @@ class RequestTest < Test::Unit::TestCase
|
|
141
143
|
end
|
142
144
|
|
143
145
|
should_log_including "Example 2 request"
|
144
|
-
should_have_config_afterwards_including :
|
146
|
+
should_have_config_afterwards_including :labels => {"" => "HTTP"},
|
147
|
+
:label => "Example"
|
145
148
|
end
|
146
149
|
|
147
150
|
context "inside a config block of :label => 'Example 2' nested inside a config block of :label => 'Example'" do
|
@@ -155,13 +158,14 @@ class RequestTest < Test::Unit::TestCase
|
|
155
158
|
end
|
156
159
|
|
157
160
|
should_log_including "Example 2 request"
|
158
|
-
should_have_config_afterwards_including :
|
161
|
+
should_have_config_afterwards_including :labels => {"" => "HTTP"},
|
162
|
+
:label => nil
|
159
163
|
end
|
160
164
|
|
161
|
-
context "wth a global config including :
|
165
|
+
context "wth a global config including :labels => {'example.com' => 'Example'} but inside a config block of :label => 'Example 3' nested inside a config block of :label => 'Example 2'" do
|
162
166
|
setup do
|
163
167
|
FakeWeb.register_uri(:get, "http://example.com/test", :status => [200, "OK"])
|
164
|
-
Samuel.config[:
|
168
|
+
Samuel.config[:labels] = {'example.com' => 'Example'}
|
165
169
|
Samuel.with_config :label => "Example 2" do
|
166
170
|
Samuel.with_config :label => "Example 3" do
|
167
171
|
open "http://example.com/test"
|
@@ -170,7 +174,18 @@ class RequestTest < Test::Unit::TestCase
|
|
170
174
|
end
|
171
175
|
|
172
176
|
should_log_including "Example 3 request"
|
173
|
-
should_have_config_afterwards_including :
|
177
|
+
should_have_config_afterwards_including :labels => {'example.com' => 'Example'},
|
178
|
+
:label => nil
|
179
|
+
end
|
180
|
+
|
181
|
+
context "with a global config including :labels => {'example.com' => 'Example API'}" do
|
182
|
+
setup do
|
183
|
+
FakeWeb.register_uri(:get, "http://example.com/test", :status => [200, "OK"])
|
184
|
+
Samuel.config[:labels] = {'example.com' => 'Example API'}
|
185
|
+
open "http://example.com/test"
|
186
|
+
end
|
187
|
+
|
188
|
+
should_log_including "Example API request"
|
174
189
|
end
|
175
190
|
|
176
191
|
end
|
data/test/samuel_test.rb
CHANGED
@@ -35,7 +35,7 @@ class SamuelTest < Test::Unit::TestCase
|
|
35
35
|
should "reset the config to default vaules" do
|
36
36
|
Samuel.config = {:foo => "bar"}
|
37
37
|
Samuel.reset_config
|
38
|
-
assert_equal({:label => "HTTP", :filtered_params => []}, Samuel.config)
|
38
|
+
assert_equal({:label => nil, :labels => {"" => "HTTP"}, :filtered_params => []}, Samuel.config)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samuel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kampmeier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-15 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|