low 0.0.13 → 0.0.14
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/lib/low/rack/request_logger.rb +4 -1
- data/lib/low/version.rb +1 -1
- data/spec/low/rack/request_logger_spec.rb +14 -6
- metadata +1 -1
@@ -7,12 +7,15 @@ module Low
|
|
7
7
|
# `Low::ScopedLogger`, with `#level` and `#scope` taken from env.
|
8
8
|
class RequestLogger
|
9
9
|
|
10
|
+
DEFAULT_KEY = 'rack.logger'
|
11
|
+
|
10
12
|
def initialize(app, opts = {})
|
11
13
|
@app = app
|
14
|
+
@key = opts[:key] || DEFAULT_KEY
|
12
15
|
end
|
13
16
|
|
14
17
|
def call(env)
|
15
|
-
env[
|
18
|
+
env[@key] = logger(env)
|
16
19
|
@app.call(env)
|
17
20
|
end
|
18
21
|
|
data/lib/low/version.rb
CHANGED
@@ -4,19 +4,27 @@ require 'low/scoped_logger'
|
|
4
4
|
require 'low/rack/request_logger'
|
5
5
|
|
6
6
|
describe Low::Rack::RequestLogger do
|
7
|
-
def test_app
|
8
|
-
lambda do |env|
|
9
|
-
[200, {'Content-Type' => 'text/plain'}, env['rack.logger']]
|
10
|
-
end
|
11
|
-
end
|
12
7
|
|
13
8
|
it 'should set rack.logger to an instance of `Low::ScopedLogger` with scope set to \'request_id\'
|
14
9
|
and level set to \'low.log_level\'' do
|
15
|
-
|
10
|
+
app = lambda do |env|
|
11
|
+
[200, {'Content-Type' => 'text/plain'}, env['rack.logger']]
|
12
|
+
end
|
13
|
+
rack = Low::Rack::RequestLogger.new app
|
16
14
|
response = rack.call({'request_id' => 'abc123', 'low.log_level' => Logger::FATAL})
|
17
15
|
logger = response[2]
|
18
16
|
logger.should be_a(Low::ScopedLogger)
|
19
17
|
logger.scope.should == 'abc123'
|
20
18
|
logger.level.should == Logger::FATAL
|
21
19
|
end
|
20
|
+
|
21
|
+
it 'should set the specified logger key' do
|
22
|
+
app = lambda do |env|
|
23
|
+
[200, {'Content-Type' => 'text/plain'}, env['another.logger']]
|
24
|
+
end
|
25
|
+
rack = Low::Rack::RequestLogger.new app, key: 'another.logger'
|
26
|
+
response = rack.call({})
|
27
|
+
response[2].should be_a(Low::ScopedLogger)
|
28
|
+
end
|
29
|
+
|
22
30
|
end
|