faraday-logging-color_formatter 0.1.1 → 0.2.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -0
- data/lib/faraday/logging/color_formatter/formatter.rb +12 -4
- data/lib/faraday/logging/color_formatter/version.rb +1 -1
- 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: 1253416d51b114229d35aa77e5ebd0529f5107919b41629dd292bfa43d23ce8f
|
4
|
+
data.tar.gz: cd4d8864d2ed7daf33dc5e1a2eb1efc5af2a2002c831bcaa741529c36fd1a290
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc451459e650541b1f3f8a1b4f4c4b48df34c4b86d5a10f941bdd8bbe196bc4b713f5e8a0213b463dd91447fde2e7aa6132bb8ba2868873716c44343f088d85c
|
7
|
+
data.tar.gz: 98440c5596cf19c8e346ebd80c2cda383f52618c2dc67ae1f5e06acd48b86dc5fb1ee1c6cb943b9c8086bc6dde527ce5d45ee9335a382e82ef8b0bfe5628906a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,12 @@ And then add the `Faraday::Logging::ColorFormatter` formatter to your logger mid
|
|
34
34
|
conn.response :logger, ActiveSupport::Logger.new($stdout), formatter: Faraday::Logging::ColorFormatter
|
35
35
|
end
|
36
36
|
|
37
|
+
If you want to replace the default `HTTP Request` and `HTTP Response` prefixes or adjust the indentation, pass in a `prefix` hash with your own values.
|
38
|
+
|
39
|
+
connection = Faraday.new(url: 'http://httpbingo.org') do |conn|
|
40
|
+
conn.response :logger, ActiveSupport::Logger.new($stdout), formatter: Faraday::Logging::ColorFormatter, prefix: { request: 'request', response: 'response', indent: 2 }
|
41
|
+
end
|
42
|
+
|
37
43
|
## Development
|
38
44
|
|
39
45
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests and `rake rubocop` to run the linters. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -8,11 +8,17 @@ module Faraday
|
|
8
8
|
class Formatter < Faraday::Logging::Formatter
|
9
9
|
ANSI_COLORS = { red: "\e[31m", green: "\e[32m", yellow: "\e[33m", blue: "\e[34m", magenta: "\e[35m", cyan: "\e[36m", reset: "\e[0m" }.freeze
|
10
10
|
|
11
|
+
def initialize(logger:, options:)
|
12
|
+
@prefix = { request: 'HTTP Request', response: 'HTTP Response', indent: 0 }.merge(options.delete(:prefix) || {})
|
13
|
+
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
11
17
|
def request(env)
|
12
|
-
http_request_term = in_color(:blue) {
|
18
|
+
http_request_term = prefix[:request].nil? || prefix[:request].strip.empty? ? nil : in_color(:blue) { "#{prefix[:request]} " }
|
13
19
|
http_request_log = in_color(request_log_color(env.method)) { "#{env.method.upcase} #{apply_filters(env.url.to_s)}" }
|
14
20
|
|
15
|
-
request_log = proc { "#{http_request_term}
|
21
|
+
request_log = proc { "#{' ' * prefix[:indent]}#{http_request_term}#{http_request_log}" }
|
16
22
|
public_send(log_level, &request_log)
|
17
23
|
|
18
24
|
log_headers(nil, env.request_headers) if log_headers?(:request)
|
@@ -20,10 +26,10 @@ module Faraday
|
|
20
26
|
end
|
21
27
|
|
22
28
|
def response(env)
|
23
|
-
http_response_term = in_color(:blue) {
|
29
|
+
http_response_term = prefix[:response].nil? || prefix[:response].strip.empty? ? nil : in_color(:blue) { "#{prefix[:response]} " }
|
24
30
|
http_response_log = in_color(response_log_color(env.status)) { "Status #{env.status}" }
|
25
31
|
|
26
|
-
status = proc { "#{http_response_term}
|
32
|
+
status = proc { "#{' ' * prefix[:indent]}#{http_response_term}#{http_response_log}" }
|
27
33
|
public_send(log_level, &status)
|
28
34
|
|
29
35
|
log_headers(nil, env.response_headers) if log_headers?(:response)
|
@@ -32,6 +38,8 @@ module Faraday
|
|
32
38
|
|
33
39
|
private
|
34
40
|
|
41
|
+
attr_reader :prefix
|
42
|
+
|
35
43
|
def in_color(color)
|
36
44
|
"#{ANSI_COLORS[color]}#{yield}#{ANSI_COLORS[:reset]}"
|
37
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-logging-color_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kobus Joubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|