rails_api_logger 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -3
- data/README.md +1 -0
- data/lib/rails_api_logger.rb +1 -0
- data/lib/rails_api_logger/inbound_requests_logger.rb +1 -1
- data/lib/rails_api_logger/inbound_requests_logger_middleware.rb +1 -1
- data/lib/rails_api_logger/request_log.rb +25 -2
- data/lib/rails_api_logger/version.rb +1 -1
- data/rails_api_logger.gemspec +5 -2
- metadata +45 -4
- data/Gemfile.lock +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f13c4887a4835f4654755c70748676106fd20649619fad63084f6a0fc2c9787
|
4
|
+
data.tar.gz: 42309cf04f2727b76bb88818e3c694cf5ba80d63f0535b4223c2a4a29d93db99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7b7c914d762daeba5c54d617f4d6802d506b72db0023775ad3548820327e2199608a40af3534b28224744ebcfcd9e8944d2cb313dc9fc30440e8bcfc377711a
|
7
|
+
data.tar.gz: 16dbc39a87e88cbed4eadc2dccd24eac17140c349addd336e32f6c55b895316752f07bbc49c7b2b953cbfc3bbb854cf8126b786f0b4298a7df4f941de9b22d81
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/rails_api_logger.rb
CHANGED
@@ -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
|
|
@@ -17,7 +17,7 @@ class InboundRequestLoggerMiddleware
|
|
17
17
|
end
|
18
18
|
status, headers, body = @app.call(env)
|
19
19
|
if logging
|
20
|
-
@inbound_request_log.
|
20
|
+
@inbound_request_log.update_columns(response_body: parsed_body(body), response_code: status)
|
21
21
|
end
|
22
22
|
[status, headers, body]
|
23
23
|
end
|
@@ -8,12 +8,12 @@ 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
|
-
|
15
|
+
request_body = (request.body.respond_to?(:read) ? request.body.read : request.body)
|
16
|
+
body = request_body ? request_body.dup.force_encoding("UTF-8") : nil
|
17
17
|
begin
|
18
18
|
body = JSON.parse(body) if body.present?
|
19
19
|
rescue JSON::ParserError
|
@@ -21,4 +21,27 @@ class RequestLog < ActiveRecord::Base
|
|
21
21
|
end
|
22
22
|
create(path: request.path, request_body: body, method: request.method)
|
23
23
|
end
|
24
|
+
|
25
|
+
def formatted_request_body
|
26
|
+
formatted_body(request_body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def formatted_response_body
|
30
|
+
formatted_body(response_body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def formatted_body(body)
|
34
|
+
if body.is_a?(Hash)
|
35
|
+
JSON.pretty_generate(body)
|
36
|
+
else
|
37
|
+
xml = Nokogiri::XML(body)
|
38
|
+
if xml.errors.any?
|
39
|
+
body
|
40
|
+
else
|
41
|
+
xml.to_xml(indent: 2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue
|
45
|
+
body
|
46
|
+
end
|
24
47
|
end
|
data/rails_api_logger.gemspec
CHANGED
@@ -25,9 +25,12 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_dependency
|
29
|
-
spec.add_dependency
|
28
|
+
spec.add_dependency "railties", ">= 4.1.0"
|
29
|
+
spec.add_dependency "activerecord", ">= 4.1.0"
|
30
|
+
spec.add_dependency "nokogiri"
|
30
31
|
|
31
32
|
spec.add_development_dependency "sqlite3", "~> 1.4.0"
|
32
33
|
spec.add_development_dependency "standard", "~> 0.13.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
36
|
end
|
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.3.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: 2021-
|
11
|
+
date: 2021-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 4.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: sqlite3
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,34 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 0.13.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '12.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '12.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
69
111
|
description: Log inbound and outbound API requests in your Rails application
|
70
112
|
email:
|
71
113
|
- alessandro.rodi@renuo.ch
|
@@ -81,7 +123,6 @@ files:
|
|
81
123
|
- CHANGELOG.md
|
82
124
|
- CODE_OF_CONDUCT.md
|
83
125
|
- Gemfile
|
84
|
-
- Gemfile.lock
|
85
126
|
- LICENSE.txt
|
86
127
|
- README.md
|
87
128
|
- Rakefile
|
@@ -120,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
161
|
- !ruby/object:Gem::Version
|
121
162
|
version: '0'
|
122
163
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.2.16
|
124
165
|
signing_key:
|
125
166
|
specification_version: 4
|
126
167
|
summary: "Log API requests like a king \U0001F451"
|
data/Gemfile.lock
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rails_api_logger (0.2.1)
|
5
|
-
activerecord (>= 4.1.0)
|
6
|
-
railties (>= 4.1.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionpack (6.1.1)
|
12
|
-
actionview (= 6.1.1)
|
13
|
-
activesupport (= 6.1.1)
|
14
|
-
rack (~> 2.0, >= 2.0.9)
|
15
|
-
rack-test (>= 0.6.3)
|
16
|
-
rails-dom-testing (~> 2.0)
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
-
actionview (6.1.1)
|
19
|
-
activesupport (= 6.1.1)
|
20
|
-
builder (~> 3.1)
|
21
|
-
erubi (~> 1.4)
|
22
|
-
rails-dom-testing (~> 2.0)
|
23
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
-
activemodel (6.1.1)
|
25
|
-
activesupport (= 6.1.1)
|
26
|
-
activerecord (6.1.1)
|
27
|
-
activemodel (= 6.1.1)
|
28
|
-
activesupport (= 6.1.1)
|
29
|
-
activesupport (6.1.1)
|
30
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
-
i18n (>= 1.6, < 2)
|
32
|
-
minitest (>= 5.1)
|
33
|
-
tzinfo (~> 2.0)
|
34
|
-
zeitwerk (~> 2.3)
|
35
|
-
ast (2.4.2)
|
36
|
-
builder (3.2.4)
|
37
|
-
concurrent-ruby (1.1.8)
|
38
|
-
crass (1.0.6)
|
39
|
-
diff-lcs (1.4.4)
|
40
|
-
erubi (1.10.0)
|
41
|
-
i18n (1.8.9)
|
42
|
-
concurrent-ruby (~> 1.0)
|
43
|
-
loofah (2.9.0)
|
44
|
-
crass (~> 1.0.2)
|
45
|
-
nokogiri (>= 1.5.9)
|
46
|
-
method_source (1.0.0)
|
47
|
-
minitest (5.14.4)
|
48
|
-
nokogiri (1.11.1-x86_64-darwin)
|
49
|
-
racc (~> 1.4)
|
50
|
-
parallel (1.20.1)
|
51
|
-
parser (3.0.0.0)
|
52
|
-
ast (~> 2.4.1)
|
53
|
-
racc (1.5.2)
|
54
|
-
rack (2.2.3)
|
55
|
-
rack-test (1.1.0)
|
56
|
-
rack (>= 1.0, < 3)
|
57
|
-
rails-dom-testing (2.0.3)
|
58
|
-
activesupport (>= 4.2.0)
|
59
|
-
nokogiri (>= 1.6)
|
60
|
-
rails-html-sanitizer (1.3.0)
|
61
|
-
loofah (~> 2.3)
|
62
|
-
railties (6.1.1)
|
63
|
-
actionpack (= 6.1.1)
|
64
|
-
activesupport (= 6.1.1)
|
65
|
-
method_source
|
66
|
-
rake (>= 0.8.7)
|
67
|
-
thor (~> 1.0)
|
68
|
-
rainbow (3.0.0)
|
69
|
-
rake (12.3.3)
|
70
|
-
regexp_parser (2.0.3)
|
71
|
-
rexml (3.2.4)
|
72
|
-
rspec (3.10.0)
|
73
|
-
rspec-core (~> 3.10.0)
|
74
|
-
rspec-expectations (~> 3.10.0)
|
75
|
-
rspec-mocks (~> 3.10.0)
|
76
|
-
rspec-core (3.10.0)
|
77
|
-
rspec-support (~> 3.10.0)
|
78
|
-
rspec-expectations (3.10.0)
|
79
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
-
rspec-support (~> 3.10.0)
|
81
|
-
rspec-mocks (3.10.0)
|
82
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
-
rspec-support (~> 3.10.0)
|
84
|
-
rspec-support (3.10.0)
|
85
|
-
rubocop (1.10.0)
|
86
|
-
parallel (~> 1.10)
|
87
|
-
parser (>= 3.0.0.0)
|
88
|
-
rainbow (>= 2.2.2, < 4.0)
|
89
|
-
regexp_parser (>= 1.8, < 3.0)
|
90
|
-
rexml
|
91
|
-
rubocop-ast (>= 1.2.0, < 2.0)
|
92
|
-
ruby-progressbar (~> 1.7)
|
93
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
94
|
-
rubocop-ast (1.4.1)
|
95
|
-
parser (>= 2.7.1.5)
|
96
|
-
rubocop-performance (1.9.2)
|
97
|
-
rubocop (>= 0.90.0, < 2.0)
|
98
|
-
rubocop-ast (>= 0.4.0)
|
99
|
-
ruby-progressbar (1.11.0)
|
100
|
-
sqlite3 (1.4.2)
|
101
|
-
standard (0.13.0)
|
102
|
-
rubocop (= 1.10.0)
|
103
|
-
rubocop-performance (= 1.9.2)
|
104
|
-
thor (1.1.0)
|
105
|
-
tzinfo (2.0.4)
|
106
|
-
concurrent-ruby (~> 1.0)
|
107
|
-
unicode-display_width (2.0.0)
|
108
|
-
zeitwerk (2.4.2)
|
109
|
-
|
110
|
-
PLATFORMS
|
111
|
-
ruby
|
112
|
-
|
113
|
-
DEPENDENCIES
|
114
|
-
rails_api_logger!
|
115
|
-
rake (~> 12.0)
|
116
|
-
rspec (~> 3.0)
|
117
|
-
sqlite3 (~> 1.4.0)
|
118
|
-
standard (~> 0.13.0)
|
119
|
-
|
120
|
-
BUNDLED WITH
|
121
|
-
2.1.4
|