rails_api_logger 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/rails_api_logger/request_log.rb +14 -8
- 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: bab320d5ee753c378838802e7213986a2359270f4f2a7ee89d3a1b2838bee6b3
|
4
|
+
data.tar.gz: 55c1d432d0df101d1c3b1a4ecd2ce44a3ad2dbd4916ef53a284a5d39ce98ed1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4c6e644ae4091d0a814227208f669dd992e86a6b77f27c419fb3b6420ba247816196f2cf3e601ddf5f00b4fac3b3ce026b41e5b0cb3b21713302984a1aa90ee
|
7
|
+
data.tar.gz: 770630cb4413b5732fb7326d8a387be4937df558e04660b80920b5252f789376ecef515bc10d874eccf21c1b41235643f4bfcc32c6b8a15d9e095a5477532a1e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# 0.8.0
|
2
|
+
* 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.
|
3
|
+
|
1
4
|
# 0.7.0
|
2
5
|
* Fix an issue in the middleware where the request body was not read correctly if there were encoding issues.
|
3
6
|
* Improved documentation about outboud request logging.
|
@@ -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.0
|
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-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|