lhc 10.1.8 → 10.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhc/interceptors/logging.rb +18 -2
- data/lib/lhc/request.rb +2 -1
- data/lib/lhc/version.rb +1 -1
- data/spec/interceptors/logging/main_spec.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc6f67c5590c8d29e3975dd469db633f164cfe3ba7109d0219757f8a6d5b4d2
|
4
|
+
data.tar.gz: 14b0ad5191daa8a24ac9179705d6f984ff125db3a800fa7cb995643fb0d3201f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e5e21160102890932469d254ded92bdcd7beac5a922cede08a52b431dc3f70fc419f0a3b8eac64cf4c68dc0190bec4d9eb6f7d0cb232803e0d805ac691b8e5b
|
7
|
+
data.tar.gz: 48fdca5e9f48be632024b24b7be5819551ca03316f20509c679652eb1b79feff662d4e7b1533434bac02cfcd9f1376c2d366399346125db8e256bbba9a4ed05f
|
@@ -8,14 +8,30 @@ class LHC::Logging < LHC::Interceptor
|
|
8
8
|
def before_request
|
9
9
|
return unless logger
|
10
10
|
logger.info(
|
11
|
-
|
11
|
+
[
|
12
|
+
'Before LHC request',
|
13
|
+
"<#{request.object_id}>",
|
14
|
+
request.method.upcase,
|
15
|
+
"#{request.url} at #{Time.now.iso8601}",
|
16
|
+
"Params=#{request.params}",
|
17
|
+
"Headers=#{request.headers}",
|
18
|
+
request.source ? "\nCalled from #{request.source}" : nil
|
19
|
+
].compact.join(' ')
|
12
20
|
)
|
13
21
|
end
|
14
22
|
|
15
23
|
def after_response
|
16
24
|
return unless logger
|
17
25
|
logger.info(
|
18
|
-
|
26
|
+
[
|
27
|
+
'After LHC response for request',
|
28
|
+
"<#{request.object_id}>",
|
29
|
+
request.method.upcase,
|
30
|
+
"#{request.url} at #{Time.now.iso8601}",
|
31
|
+
"Time=#{response.time_ms}ms",
|
32
|
+
"URL=#{response.effective_url}",
|
33
|
+
request.source ? "\nCalled from #{request.source}" : nil
|
34
|
+
].compact.join(' ')
|
19
35
|
)
|
20
36
|
end
|
21
37
|
end
|
data/lib/lhc/request.rb
CHANGED
@@ -12,10 +12,11 @@ class LHC::Request
|
|
12
12
|
|
13
13
|
TYPHOEUS_OPTIONS ||= [:params, :method, :body, :headers, :follow_location, :params_encoding]
|
14
14
|
|
15
|
-
attr_accessor :response, :options, :raw, :format, :error_handler, :errors_ignored
|
15
|
+
attr_accessor :response, :options, :raw, :format, :error_handler, :errors_ignored, :source
|
16
16
|
|
17
17
|
def initialize(options, self_executing = true)
|
18
18
|
self.errors_ignored = (options.fetch(:ignored_errors, []) || []).compact
|
19
|
+
self.source = options&.dig(:source)
|
19
20
|
self.options = format!(options.deep_dup || {})
|
20
21
|
self.error_handler = options.delete :error_handler
|
21
22
|
use_configured_endpoint!
|
data/lib/lhc/version.rb
CHANGED
@@ -8,16 +8,30 @@ describe LHC::Logging do
|
|
8
8
|
before(:each) do
|
9
9
|
LHC.config.interceptors = [LHC::Logging]
|
10
10
|
LHC::Logging.logger = logger
|
11
|
+
stub_request(:get, 'http://local.ch').to_return(status: 200)
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'does log information before and after every request made with LHC' do
|
14
|
-
stub_request(:get, 'http://local.ch').to_return(status: 200)
|
15
15
|
LHC.get('http://local.ch')
|
16
16
|
expect(logger).to have_received(:info).once.with(
|
17
|
-
%r{Before LHC request<\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Params={} Headers={.*?}}
|
17
|
+
%r{Before LHC request <\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Params={} Headers={.*?}}
|
18
18
|
)
|
19
19
|
expect(logger).to have_received(:info).once.with(
|
20
|
-
%r{After LHC response for request<\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Time=0ms URL=http://local.ch:80/}
|
20
|
+
%r{After LHC response for request <\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Time=0ms URL=http://local.ch:80/}
|
21
21
|
)
|
22
22
|
end
|
23
|
+
|
24
|
+
context 'source' do
|
25
|
+
let(:source) { '/Users/Sebastian/LHC/test.rb' }
|
26
|
+
|
27
|
+
it 'does log the source if provided as option' do
|
28
|
+
LHC.get('http://local.ch', source: source)
|
29
|
+
expect(logger).to have_received(:info).once.with(
|
30
|
+
%r{Before LHC request <\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Params={} Headers={.*?} \nCalled from #{source}}
|
31
|
+
)
|
32
|
+
expect(logger).to have_received(:info).once.with(
|
33
|
+
%r{After LHC response for request <\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Time=0ms URL=http://local.ch:80/ \nCalled from #{source}}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
23
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.
|
4
|
+
version: 10.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|