faraday-detailed_logger 2.4.2 → 2.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a686fbdcac03dc9553636285c80a55e6ecdf61215071e97c414a3f895f384bbc
4
- data.tar.gz: 7a6651d0800697f224c3f9332a21e35f2c0736611a9508b99593b0284e9f88cd
3
+ metadata.gz: 743670ebe4c7a46ecd82eaa2adc20d41ebc5dae3adb4786402105d9fcf92ce4e
4
+ data.tar.gz: 986b9fcef32c461f74a85a2e70b6989ebe265d58aed99b6b1acfb100c6ab8b27
5
5
  SHA512:
6
- metadata.gz: 0babd0756cefda4d3225a942841b2f98d3cdb45cc5ef01374807379462e8b0920d7bfa517023e0fe5f759d628304d015d9996f161a53ef6288aec5edfc080d19
7
- data.tar.gz: 81c824acc1708a8fb4229da7830bd17c13b1badd586e2f6ffe1382aa34456983515a21fc63fb6eef94cc6d7c66acc98f1389be28a5da60ce130888f05d72dec5
6
+ metadata.gz: 036174605b88b0cb52f138e94b239a2c62ecd577ca91dc19f9e729bd674fe0eb73f4a92d0f32b992a677a7ef83021deaf359522072898b5c501381252591a473
7
+ data.tar.gz: ccd1cde9ad73aadb412d357bc52e24ad41c20dc091954f91364ad8610cf3919c20e685bce8f82bc8a2963e9326c8e031f7fc6826277f7a2aa88192f5a5590b46
data/Appraisals CHANGED
@@ -12,6 +12,10 @@ appraise 'faraday-1.x' do
12
12
  gem 'faraday', '~> 1.0'
13
13
  end
14
14
 
15
+ appraise 'faraday-2.x' do
16
+ gem 'faraday', '~> 2.0'
17
+ end
18
+
15
19
  appraise 'faraday-latest' do
16
20
  gem 'faraday'
17
21
  end
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@
7
7
 
8
8
  * No significant changes.
9
9
 
10
+ ## [2.5.0][] / 2022-01-23
11
+
12
+ * Add faraday 2 support.
13
+ * Extract an initial internal cURL formatter
14
+
10
15
  ## [2.4.2][] / 2021-11-09
11
16
 
12
17
  * Revert zeitwerk autoloading changes.
@@ -85,4 +90,5 @@
85
90
  [2.4.0]: https://github.com/envylabs/faraday-detailed_logger/compare/v2.3.0...v2.4.0
86
91
  [2.4.1]: https://github.com/envylabs/faraday-detailed_logger/compare/v2.4.0...v2.4.1
87
92
  [2.4.2]: https://github.com/envylabs/faraday-detailed_logger/compare/v2.4.1...v2.4.2
88
- [HEAD]: https://github.com/envylabs/faraday-detailed_logger/compare/v2.4.2...main
93
+ [2.5.0]: https://github.com/envylabs/faraday-detailed_logger/compare/v2.4.2...v2.5.0
94
+ [HEAD]: https://github.com/envylabs/faraday-detailed_logger/compare/v2.5.0...main
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.require_paths = ['lib']
33
33
 
34
- spec.add_runtime_dependency 'faraday', '>= 0.16', '< 2'
34
+ spec.add_runtime_dependency 'faraday', '>= 0.16', '< 3'
35
35
 
36
36
  spec.add_development_dependency 'appraisal', '~> 2.0'
37
37
  spec.add_development_dependency 'bundler', '~> 2.0'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module DetailedLogger
5
+ module CurlFormatter
6
+ def self.request(env)
7
+ "#{env[:method].upcase} #{env[:url]}"
8
+ end
9
+
10
+ def self.request_body(env)
11
+ curl_output(env[:request_headers], env[:body]).inspect
12
+ end
13
+
14
+ def self.response(env)
15
+ "HTTP #{env[:status]}"
16
+ end
17
+
18
+ def self.response_body(env)
19
+ curl_output(env[:response_headers], env[:body]).inspect
20
+ end
21
+
22
+ private
23
+
24
+ def self.curl_output(headers, body)
25
+ string = headers.to_a.sort_by(&:first).map { |k, v| "#{k}: #{v}" }.join("\n")
26
+ string + "\n\n#{body}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Faraday
6
+ module DetailedLogger
7
+ # A Faraday middleware used for providing debug-level logging information.
8
+ # The request and response logs follow very closely with cURL output for
9
+ # ease of understanding.
10
+ #
11
+ # Be careful about your log level settings when using this middleware,
12
+ # especially in a production environment. With a DEBUG level log enabled,
13
+ # there will be potential information security concerns, because the
14
+ # request and response headers and bodies will be logged out. At an INFO or
15
+ # greater level, this is not a concern.
16
+ #
17
+ class Middleware < Faraday::Middleware
18
+ attr_reader :logger
19
+ attr_reader :tags
20
+
21
+ # Internal: Used as the Middleware's logger in the case that an explicit
22
+ # logger is not provided.
23
+ #
24
+ # Returns a Logger instance.
25
+ #
26
+ def self.default_logger
27
+ require 'logger'
28
+ ::Logger.new($stdout)
29
+ end
30
+
31
+ # Public: Initialize a new Logger middleware.
32
+ #
33
+ # app - A Faraday-compatible middleware stack or application.
34
+ # logger - A Logger-compatible object to which the log information will
35
+ # be recorded.
36
+ # tags - An optional array of tags to apply to the log output.
37
+ #
38
+ # Returns a Logger instance.
39
+ #
40
+ def initialize(app, logger = nil, *tags)
41
+ super(app)
42
+ @formatter = CurlFormatter
43
+ @logger = TaggedLogging.new(logger || self.class.default_logger)
44
+ @tags = tags
45
+ end
46
+
47
+ # Public: Used by Faraday to execute the middleware during the
48
+ # request/response cycle.
49
+ #
50
+ # env - A Faraday-compatible request environment.
51
+ #
52
+ # Returns the result of the parent application execution.
53
+ #
54
+ def call(env)
55
+ super
56
+ rescue
57
+ logger.error do
58
+ "#{$!.class.name} - #{$!.message} (#{$!.backtrace.first})"
59
+ end
60
+ raise
61
+ end
62
+
63
+ # Internal: Used by Faraday as a callback hook to process a network
64
+ # response after it has completed.
65
+ #
66
+ # env - A Faraday-compatible response environment.
67
+ #
68
+ # Returns nothing.
69
+ #
70
+ def on_complete(env)
71
+ status = env[:status]
72
+
73
+ logger.tagged(*tags) do
74
+ log_response_status(status) { formatter.response(env) }
75
+ logger.debug { formatter.response_body(env) }
76
+ end
77
+ end
78
+
79
+ # Public: Used by Faraday as a callback hook to process a network request
80
+ # before it has been made.
81
+ #
82
+ # env - A Faraday-compatible request environment.
83
+ #
84
+ # Returns nothing.
85
+ #
86
+ def on_request(env)
87
+ logger.tagged(*tags) do
88
+ logger.info { formatter.request(env) }
89
+ logger.debug { formatter.request_body(env) }
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ attr_reader :formatter
96
+
97
+ def log_response_status(status, &block)
98
+ case status
99
+ when 200..399
100
+ logger.info(&block)
101
+ else
102
+ logger.warn(&block)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Faraday
6
+ module DetailedLogger
7
+ # A Faraday middleware used for providing debug-level logging information.
8
+ # The request and response logs follow very closely with cURL output for
9
+ # ease of understanding.
10
+ #
11
+ # Be careful about your log level settings when using this middleware,
12
+ # especially in a production environment. With a DEBUG level log enabled,
13
+ # there will be potential information security concerns, because the
14
+ # request and response headers and bodies will be logged out. At an INFO or
15
+ # greater level, this is not a concern.
16
+ #
17
+ class Middleware < Faraday::Response::Middleware
18
+ attr_reader :logger
19
+ attr_reader :tags
20
+
21
+ # Internal: Used as the Middleware's logger in the case that an explicit
22
+ # logger is not provided.
23
+ #
24
+ # Returns a Logger instance.
25
+ #
26
+ def self.default_logger
27
+ require 'logger'
28
+ ::Logger.new($stdout)
29
+ end
30
+
31
+ # Public: Initialize a new Logger middleware.
32
+ #
33
+ # app - A Faraday-compatible middleware stack or application.
34
+ # logger - A Logger-compatible object to which the log information will
35
+ # be recorded.
36
+ # tags - An optional array of tags to apply to the log output.
37
+ #
38
+ # Returns a Logger instance.
39
+ #
40
+ def initialize(app, logger = nil, *tags)
41
+ super(app)
42
+ @formatter = CurlFormatter
43
+ @logger = TaggedLogging.new(logger || self.class.default_logger)
44
+ @tags = tags
45
+ end
46
+
47
+ # Public: Used by Faraday to execute the middleware during the
48
+ # request/response cycle.
49
+ #
50
+ # env - A Faraday-compatible request environment.
51
+ #
52
+ # Returns the result of the parent application execution.
53
+ #
54
+ def call(env)
55
+ logger.tagged(*tags) do
56
+ logger.info { formatter.request(env) }
57
+ logger.debug { formatter.request_body(env) }
58
+ end
59
+ super
60
+ rescue
61
+ logger.error do
62
+ "#{$!.class.name} - #{$!.message} (#{$!.backtrace.first})"
63
+ end
64
+ raise
65
+ end
66
+
67
+ # Internal: Used by Faraday as a callback hook to process a network
68
+ # response after it has completed.
69
+ #
70
+ # env - A Faraday-compatible response environment.
71
+ #
72
+ # Returns nothing.
73
+ #
74
+ def on_complete(env)
75
+ status = env[:status]
76
+
77
+ logger.tagged(*tags) do
78
+ log_response_status(status) { formatter.response(env) }
79
+ logger.debug { formatter.response_body(env) }
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ attr_reader :formatter
86
+
87
+ def log_response_status(status, &block)
88
+ case status
89
+ when 200..399
90
+ logger.info(&block)
91
+ else
92
+ logger.warn(&block)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,108 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'faraday/detailed_logger/curl_formatter'
4
5
  require 'faraday/detailed_logger/tagged_logging'
5
6
 
6
- module Faraday
7
- module DetailedLogger
8
- # A Faraday middleware used for providing debug-level logging information.
9
- # The request and response logs follow very closely with cURL output for
10
- # ease of understanding.
11
- #
12
- # Be careful about your log level settings when using this middleware,
13
- # especially in a production environment. With a DEBUG level log enabled,
14
- # there will be potential information security concerns, because the
15
- # request and response headers and bodies will be logged out. At an INFO or
16
- # greater level, this is not a concern.
17
- #
18
- class Middleware < Faraday::Response::Middleware
19
- attr_reader :logger
20
- attr_reader :tags
21
-
22
- # Internal: Used as the Middleware's logger in the case that an explicit
23
- # logger is not provided.
24
- #
25
- # Returns a Logger instance.
26
- #
27
- def self.default_logger
28
- require 'logger'
29
- ::Logger.new($stdout)
30
- end
31
-
32
- # Public: Initialize a new Logger middleware.
33
- #
34
- # app - A Faraday-compatible middleware stack or application.
35
- # logger - A Logger-compatible object to which the log information will
36
- # be recorded.
37
- # tags - An optional array of tags to apply to the log output.
38
- #
39
- # Returns a Logger instance.
40
- #
41
- def initialize(app, logger = nil, *tags)
42
- super(app)
43
- @logger = TaggedLogging.new(logger || self.class.default_logger)
44
- @tags = tags
45
- end
46
-
47
- # Public: Used by Faraday to execute the middleware during the
48
- # request/response cycle.
49
- #
50
- # env - A Faraday-compatible request environment.
51
- #
52
- # Returns the result of the parent application execution.
53
- #
54
- def call(env)
55
- logger.tagged(*tags) do
56
- logger.info { "#{env[:method].upcase} #{env[:url]}" }
57
- logger.debug { curl_request_output(env) }
58
- end
59
- super
60
- rescue
61
- logger.error do
62
- "#{$!.class.name} - #{$!.message} (#{$!.backtrace.first})"
63
- end
64
- raise
65
- end
66
-
67
- # Internal: Used by Faraday as a callback hook to process a network
68
- # response after it has completed.
69
- #
70
- # env - A Faraday-compatible response environment.
71
- #
72
- # Returns nothing.
73
- #
74
- def on_complete(env)
75
- status = env[:status]
76
-
77
- logger.tagged(*tags) do
78
- log_response_status(status) { "HTTP #{status}" }
79
- logger.debug { curl_response_output(env) }
80
- end
81
- end
82
-
83
- private
84
-
85
- def curl_request_output(env)
86
- curl_output(env[:request_headers], env[:body]).inspect
87
- end
88
-
89
- def curl_response_output(env)
90
- curl_output(env[:response_headers], env[:body]).inspect
91
- end
92
-
93
- def curl_output(headers, body)
94
- string = headers.to_a.sort_by(&:first).map { |k, v| "#{k}: #{v}" }.join("\n")
95
- string + "\n\n#{body}"
96
- end
97
-
98
- def log_response_status(status, &block)
99
- case status
100
- when 200..399
101
- logger.info(&block)
102
- else
103
- logger.warn(&block)
104
- end
105
- end
106
- end
107
- end
7
+ case
8
+ when Gem::Dependency.new('', '> 2.0.0.alpha.pre.1').match?('', Faraday::VERSION)
9
+ require_relative 'middleware/current'
10
+ else
11
+ require_relative 'middleware/legacy'
108
12
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module DetailedLogger
5
- VERSION = '2.4.2'
5
+ VERSION = '2.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-detailed_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envy Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-09 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.16'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '2'
22
+ version: '3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.16'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '2'
32
+ version: '3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: appraisal
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -127,13 +127,15 @@ files:
127
127
  - Appraisals
128
128
  - CHANGELOG.md
129
129
  - Gemfile
130
- - Gemfile.lock
131
130
  - LICENSE.txt
132
131
  - README.md
133
132
  - Rakefile
134
133
  - faraday-detailed_logger.gemspec
135
134
  - lib/faraday/detailed_logger.rb
135
+ - lib/faraday/detailed_logger/curl_formatter.rb
136
136
  - lib/faraday/detailed_logger/middleware.rb
137
+ - lib/faraday/detailed_logger/middleware/current.rb
138
+ - lib/faraday/detailed_logger/middleware/legacy.rb
137
139
  - lib/faraday/detailed_logger/tagged_logging.rb
138
140
  - lib/faraday/detailed_logger/version.rb
139
141
  homepage: https://github.com/envylabs/faraday-detailed_logger
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
160
  - !ruby/object:Gem::Version
159
161
  version: '0'
160
162
  requirements: []
161
- rubygems_version: 3.2.22
163
+ rubygems_version: 3.2.31
162
164
  signing_key:
163
165
  specification_version: 4
164
166
  summary: A detailed request and response logger for Faraday.
data/Gemfile.lock DELETED
@@ -1,168 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- faraday-detailed_logger (2.4.2)
5
- faraday (>= 0.16, < 2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actionpack (6.1.4.1)
11
- actionview (= 6.1.4.1)
12
- activesupport (= 6.1.4.1)
13
- rack (~> 2.0, >= 2.0.9)
14
- rack-test (>= 0.6.3)
15
- rails-dom-testing (~> 2.0)
16
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (6.1.4.1)
18
- activesupport (= 6.1.4.1)
19
- builder (~> 3.1)
20
- erubi (~> 1.4)
21
- rails-dom-testing (~> 2.0)
22
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activesupport (6.1.4.1)
24
- concurrent-ruby (~> 1.0, >= 1.0.2)
25
- i18n (>= 1.6, < 2)
26
- minitest (>= 5.1)
27
- tzinfo (~> 2.0)
28
- zeitwerk (~> 2.3)
29
- appraisal (2.4.1)
30
- bundler
31
- rake
32
- thor (>= 0.14.0)
33
- ast (2.4.2)
34
- builder (3.2.4)
35
- concurrent-ruby (1.1.9)
36
- crass (1.0.6)
37
- diff-lcs (1.4.4)
38
- erubi (1.10.0)
39
- faraday (1.8.0)
40
- faraday-em_http (~> 1.0)
41
- faraday-em_synchrony (~> 1.0)
42
- faraday-excon (~> 1.1)
43
- faraday-httpclient (~> 1.0.1)
44
- faraday-net_http (~> 1.0)
45
- faraday-net_http_persistent (~> 1.1)
46
- faraday-patron (~> 1.0)
47
- faraday-rack (~> 1.0)
48
- multipart-post (>= 1.2, < 3)
49
- ruby2_keywords (>= 0.0.4)
50
- faraday-em_http (1.0.0)
51
- faraday-em_synchrony (1.0.0)
52
- faraday-excon (1.1.0)
53
- faraday-httpclient (1.0.1)
54
- faraday-net_http (1.0.1)
55
- faraday-net_http_persistent (1.2.0)
56
- faraday-patron (1.0.0)
57
- faraday-rack (1.0.0)
58
- i18n (1.8.11)
59
- concurrent-ruby (~> 1.0)
60
- license_finder (6.14.2)
61
- bundler
62
- rubyzip (>= 1, < 3)
63
- thor (~> 1.0.1)
64
- tomlrb (>= 1.3, < 2.1)
65
- with_env (= 1.1.0)
66
- xml-simple (~> 1.1.5)
67
- loofah (2.12.0)
68
- crass (~> 1.0.2)
69
- nokogiri (>= 1.5.9)
70
- method_source (1.0.0)
71
- mini_portile2 (2.6.1)
72
- minitest (5.14.4)
73
- multipart-post (2.1.1)
74
- nokogiri (1.12.5)
75
- mini_portile2 (~> 2.6.1)
76
- racc (~> 1.4)
77
- parallel (1.21.0)
78
- parser (3.0.2.0)
79
- ast (~> 2.4.1)
80
- racc (1.6.0)
81
- rack (2.2.3)
82
- rack-test (1.1.0)
83
- rack (>= 1.0, < 3)
84
- rails-dom-testing (2.0.3)
85
- activesupport (>= 4.2.0)
86
- nokogiri (>= 1.6)
87
- rails-html-sanitizer (1.4.2)
88
- loofah (~> 2.3)
89
- railties (6.1.4.1)
90
- actionpack (= 6.1.4.1)
91
- activesupport (= 6.1.4.1)
92
- method_source
93
- rake (>= 0.13)
94
- thor (~> 1.0)
95
- rainbow (3.0.0)
96
- rake (13.0.6)
97
- regexp_parser (2.1.1)
98
- rexml (3.2.5)
99
- rspec (3.10.0)
100
- rspec-core (~> 3.10.0)
101
- rspec-expectations (~> 3.10.0)
102
- rspec-mocks (~> 3.10.0)
103
- rspec-core (3.10.1)
104
- rspec-support (~> 3.10.0)
105
- rspec-expectations (3.10.1)
106
- diff-lcs (>= 1.2.0, < 2.0)
107
- rspec-support (~> 3.10.0)
108
- rspec-mocks (3.10.2)
109
- diff-lcs (>= 1.2.0, < 2.0)
110
- rspec-support (~> 3.10.0)
111
- rspec-support (3.10.3)
112
- rubocop (1.22.3)
113
- parallel (~> 1.10)
114
- parser (>= 3.0.0.0)
115
- rainbow (>= 2.2.2, < 4.0)
116
- regexp_parser (>= 1.8, < 3.0)
117
- rexml
118
- rubocop-ast (>= 1.12.0, < 2.0)
119
- ruby-progressbar (~> 1.7)
120
- unicode-display_width (>= 1.4.0, < 3.0)
121
- rubocop-ast (1.12.0)
122
- parser (>= 3.0.1.1)
123
- rubocop-minitest (0.15.2)
124
- rubocop (>= 0.90, < 2.0)
125
- rubocop-packaging (0.5.1)
126
- rubocop (>= 0.89, < 2.0)
127
- rubocop-performance (1.12.0)
128
- rubocop (>= 1.7.0, < 2.0)
129
- rubocop-ast (>= 0.4.0)
130
- rubocop-rails (2.12.4)
131
- activesupport (>= 4.2.0)
132
- rack (>= 1.1)
133
- rubocop (>= 1.7.0, < 2.0)
134
- rubocop-rails_config (1.7.4)
135
- railties (>= 5.0)
136
- rubocop (>= 1.19)
137
- rubocop-ast (>= 1.0.1)
138
- rubocop-minitest (~> 0.15)
139
- rubocop-packaging (~> 0.5)
140
- rubocop-performance (~> 1.11)
141
- rubocop-rails (~> 2.0)
142
- ruby-progressbar (1.11.0)
143
- ruby2_keywords (0.0.5)
144
- rubyzip (2.3.2)
145
- thor (1.0.1)
146
- tomlrb (2.0.1)
147
- tzinfo (2.0.4)
148
- concurrent-ruby (~> 1.0)
149
- unicode-display_width (2.1.0)
150
- with_env (1.1.0)
151
- xml-simple (1.1.9)
152
- rexml
153
- zeitwerk (2.5.1)
154
-
155
- PLATFORMS
156
- ruby
157
-
158
- DEPENDENCIES
159
- appraisal (~> 2.0)
160
- bundler (~> 2.0)
161
- faraday-detailed_logger!
162
- license_finder (~> 6.0)
163
- rake (~> 13.0)
164
- rspec (~> 3.0)
165
- rubocop-rails_config (~> 1.3)
166
-
167
- BUNDLED WITH
168
- 2.2.30