rails_api_logger 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39be37669636bafc6de423df348669b6cd1ab0507ec309c6db0ae749dbf0ce26
|
4
|
+
data.tar.gz: f51c5532b0063d7ff54ff3a7f4743ea8a2fa24ec03ca9e858099ae6c93fed4fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac208d6e71ed50107ccc6895b24671281b8659b2cb41a4dfea59be9c4e695715126c9d61244067d2e5978f735a5d38b1483db85d0bf58fc9311cc8c4b797487
|
7
|
+
data.tar.gz: 8105b58ee606a0666db8c29b2e85c810fb042561f64fcbcf1110d7586a1ce68096908e0bb6a293c98bee12024488adffb492b41ae13a1b09460df5b6609c5749
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_api_logger (0.2.
|
4
|
+
rails_api_logger (0.2.5)
|
5
5
|
activerecord (>= 4.1.0)
|
6
6
|
railties (>= 4.1.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (6.1.
|
12
|
-
actionview (= 6.1.
|
13
|
-
activesupport (= 6.1.
|
11
|
+
actionpack (6.1.3)
|
12
|
+
actionview (= 6.1.3)
|
13
|
+
activesupport (= 6.1.3)
|
14
14
|
rack (~> 2.0, >= 2.0.9)
|
15
15
|
rack-test (>= 0.6.3)
|
16
16
|
rails-dom-testing (~> 2.0)
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
-
actionview (6.1.
|
19
|
-
activesupport (= 6.1.
|
18
|
+
actionview (6.1.3)
|
19
|
+
activesupport (= 6.1.3)
|
20
20
|
builder (~> 3.1)
|
21
21
|
erubi (~> 1.4)
|
22
22
|
rails-dom-testing (~> 2.0)
|
23
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
-
activemodel (6.1.
|
25
|
-
activesupport (= 6.1.
|
26
|
-
activerecord (6.1.
|
27
|
-
activemodel (= 6.1.
|
28
|
-
activesupport (= 6.1.
|
29
|
-
activesupport (6.1.
|
24
|
+
activemodel (6.1.3)
|
25
|
+
activesupport (= 6.1.3)
|
26
|
+
activerecord (6.1.3)
|
27
|
+
activemodel (= 6.1.3)
|
28
|
+
activesupport (= 6.1.3)
|
29
|
+
activesupport (6.1.3)
|
30
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
31
|
i18n (>= 1.6, < 2)
|
32
32
|
minitest (>= 5.1)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
nokogiri (>= 1.5.9)
|
46
46
|
method_source (1.0.0)
|
47
47
|
minitest (5.14.4)
|
48
|
-
nokogiri (1.11.
|
48
|
+
nokogiri (1.11.2-x86_64-darwin)
|
49
49
|
racc (~> 1.4)
|
50
50
|
parallel (1.20.1)
|
51
51
|
parser (3.0.0.0)
|
@@ -59,9 +59,9 @@ GEM
|
|
59
59
|
nokogiri (>= 1.6)
|
60
60
|
rails-html-sanitizer (1.3.0)
|
61
61
|
loofah (~> 2.3)
|
62
|
-
railties (6.1.
|
63
|
-
actionpack (= 6.1.
|
64
|
-
activesupport (= 6.1.
|
62
|
+
railties (6.1.3)
|
63
|
+
actionpack (= 6.1.3)
|
64
|
+
activesupport (= 6.1.3)
|
65
65
|
method_source
|
66
66
|
rake (>= 0.8.7)
|
67
67
|
thor (~> 1.0)
|
@@ -4,7 +4,7 @@ module InboundRequestsLogger
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def attach_inbound_request_loggable(loggable)
|
7
|
-
request.env["inbound_request_log"].loggable
|
7
|
+
request.env["inbound_request_log"].update(loggable: loggable) if loggable&.persisted?
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -9,22 +9,23 @@ class InboundRequestLoggerMiddleware
|
|
9
9
|
|
10
10
|
def call(env)
|
11
11
|
request = ActionDispatch::Request.new(env)
|
12
|
-
|
12
|
+
logging = log?(env, request)
|
13
|
+
if logging
|
13
14
|
@inbound_request_log = InboundRequestLog.from_request(request)
|
14
15
|
env["inbound_request_log"] = @inbound_request_log
|
15
16
|
request.body.rewind
|
16
17
|
end
|
17
18
|
status, headers, body = @app.call(env)
|
18
|
-
if
|
19
|
-
@inbound_request_log.
|
19
|
+
if logging
|
20
|
+
@inbound_request_log.update_columns(response_body: parsed_body(body), response_code: status)
|
20
21
|
end
|
21
22
|
[status, headers, body]
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
def log?(request)
|
27
|
-
|
27
|
+
def log?(env, request)
|
28
|
+
env["REQUEST_URI"] =~ path_regexp && (!only_state_change || request_with_state_change?(request))
|
28
29
|
end
|
29
30
|
|
30
31
|
def parsed_body(body)
|
@@ -8,12 +8,11 @@ class RequestLog < ActiveRecord::Base
|
|
8
8
|
|
9
9
|
scope :failed, -> { where("response_code not like '2%'") }
|
10
10
|
|
11
|
-
validates :request_body, presence: true
|
12
11
|
validates :method, presence: true
|
13
12
|
validates :path, presence: true
|
14
13
|
|
15
14
|
def self.from_request(request)
|
16
|
-
body = (request.body.respond_to?(:read) ? request.body.read : request.body).force_encoding("UTF-8")
|
15
|
+
body = (request.body.respond_to?(:read) ? request.body.read : request.body).dup.force_encoding("UTF-8")
|
17
16
|
begin
|
18
17
|
body = JSON.parse(body) if body.present?
|
19
18
|
rescue JSON::ParserError
|
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.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|