rails_api_logger 0.7.0 → 0.8.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.
- checksums.yaml +4 -4
- data/.semaphore/main-deploy.yml +1 -1
- data/.semaphore/semaphore.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/rails_api_logger/request_log.rb +16 -10
- data/lib/rails_api_logger.rb +3 -2
- data/rails_api_logger.gemspec +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: 6a49586120262a132a0601faa23ace3fb929b04f115b900a54e3d86f68f04de9
|
4
|
+
data.tar.gz: 48e8cb9dcd6172532b96ac823910965102277bb10ec39956ee006a8bdbfc71b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4468f3a723f56fd098cefe32fac6b937f63270636ac06fbd316920586516917b380120532c527d6cbd54d3808278eff28a633ad61aae5a4741a89a214d0411e2
|
7
|
+
data.tar.gz: ba10ec2838b308faad8b368ced02945a39663a34839f25b096760af9da6b108d316cf82669fd5dca5f9e2a3bccb2487bf6cb94ef84abdab5dd1743e4af7acc96
|
data/.semaphore/main-deploy.yml
CHANGED
data/.semaphore/semaphore.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.8.1
|
2
|
+
* Fix Rails 7.1 warnings.
|
3
|
+
|
4
|
+
# 0.8.0
|
5
|
+
* Add option skip_body to skip the body for request responses. Use this option when you don't want to persist the response body. `[Skipped]` will be persisted instead. This is not a breaking change.
|
6
|
+
|
1
7
|
# 0.7.0
|
2
8
|
* Fix an issue in the middleware where the request body was not read correctly if there were encoding issues.
|
3
9
|
* Improved documentation about outboud request logging.
|
data/README.md
CHANGED
@@ -103,8 +103,8 @@ end
|
|
103
103
|
OutboundRequestLog.include(OutboundRequestLogTransactionPatch)
|
104
104
|
```
|
105
105
|
|
106
|
-
|
107
|
-
|
106
|
+
You can also log the request in a separate thread to provoke the checkout of a separate database connection.
|
107
|
+
Have a look at [this example here](https://github.com/renuo/rails_api_logger/blob/28d4ced88fea5a5f4fd72f5a1db42ad4734eb547/spec/outbound_request_log_spec.rb#L28-L30).
|
108
108
|
|
109
109
|
## Log Inbound Requests
|
110
110
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class RequestLog < ActiveRecord::Base
|
2
2
|
self.abstract_class = true
|
3
3
|
|
4
|
-
serialize :request_body, JSON
|
5
|
-
serialize :response_body, JSON
|
4
|
+
serialize :request_body, coder: JSON
|
5
|
+
serialize :response_body, coder: JSON
|
6
6
|
|
7
7
|
belongs_to :loggable, optional: true, polymorphic: true
|
8
8
|
|
@@ -22,15 +22,9 @@ class RequestLog < ActiveRecord::Base
|
|
22
22
|
create(path: request.path, request_body: body, method: request.method, started_at: Time.current, loggable: loggable)
|
23
23
|
end
|
24
24
|
|
25
|
-
def from_response(response)
|
25
|
+
def from_response(response, skip_body: false)
|
26
26
|
self.response_code = response.code
|
27
|
-
|
28
|
-
begin
|
29
|
-
body = JSON.parse(body) if body.present?
|
30
|
-
rescue JSON::ParserError
|
31
|
-
body
|
32
|
-
end
|
33
|
-
self.response_body = body
|
27
|
+
self.response_body = skip_body ? "[Skipped]" : manipulate_body(response.body)
|
34
28
|
self
|
35
29
|
end
|
36
30
|
|
@@ -61,4 +55,16 @@ class RequestLog < ActiveRecord::Base
|
|
61
55
|
return if started_at.nil? || ended_at.nil?
|
62
56
|
ended_at - started_at
|
63
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def manipulate_body(body)
|
62
|
+
body_duplicate = body&.dup&.force_encoding("UTF-8")
|
63
|
+
begin
|
64
|
+
body_duplicate = JSON.parse(body_duplicate) if body_duplicate.present?
|
65
|
+
rescue JSON::ParserError
|
66
|
+
body_duplicate
|
67
|
+
end
|
68
|
+
body_duplicate
|
69
|
+
end
|
64
70
|
end
|
data/lib/rails_api_logger.rb
CHANGED
@@ -10,14 +10,15 @@ loader.setup
|
|
10
10
|
class RailsApiLogger
|
11
11
|
class Error < StandardError; end
|
12
12
|
|
13
|
-
def initialize(loggable = nil)
|
13
|
+
def initialize(loggable = nil, skip_body: false)
|
14
14
|
@loggable = loggable
|
15
|
+
@skip_body = skip_body
|
15
16
|
end
|
16
17
|
|
17
18
|
def call(url, request)
|
18
19
|
log = OutboundRequestLog.from_request(request, loggable: @loggable)
|
19
20
|
yield.tap do |response|
|
20
|
-
log.from_response(response)
|
21
|
+
log.from_response(response, skip_body: @skip_body)
|
21
22
|
end
|
22
23
|
rescue => e
|
23
24
|
log.response_body = {error: e.message}
|
data/rails_api_logger.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_api_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|