rails_api_logger 0.3.0 → 0.4.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 +13 -0
- data/lib/generators/templates/create_rails_api_logger_table.rb.tt +4 -0
- data/lib/rails_api_logger.rb +1 -0
- data/lib/rails_api_logger/inbound_requests_logger_middleware.rb +1 -1
- data/lib/rails_api_logger/request_log.rb +6 -1
- data/lib/rails_api_logger/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: 6a4cfc6305629f5d93ede15587bb8abc1f9218fa0f07fab94f3e8a9547c11609
|
4
|
+
data.tar.gz: f1c3dd646b07d8774833769d9d8417b32dae2a3ab6a1aa1297b041b6fbdf552f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cba867c8dce17d890b8c6cb3b81e92c80c0c98f85804a1ab61fba669681a31bbd0acd1b7cba4f677600e55666317a75fe30e2d0210c6f1a9e0f81e74cb691316
|
7
|
+
data.tar.gz: e45d3c7dd24c05003dd76a03c2b0f34de8563f2c65611f332a3af9ad7230af5502687b1d110f7b8ce9b1c7271cc9987440a6d127f09713d9e6e382d276f1ce3e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# 0.4.0
|
2
|
+
* Added `started_at`, `ended_at` and `duration` methods.
|
3
|
+
|
4
|
+
Migrate your tables with:
|
5
|
+
|
6
|
+
```
|
7
|
+
add_column :inbound_request_logs, :started_at, :timestamp
|
8
|
+
add_column :inbound_request_logs, :ended_at, :timestamp
|
9
|
+
add_column :outbound_request_logs, :started_at, :timestamp
|
10
|
+
add_column :outbound_request_logs, :ended_at, :timestamp
|
11
|
+
```
|
12
|
+
|
13
|
+
|
1
14
|
# 0.3.0
|
2
15
|
* Added `formatted_request_body` and `formatted_response_body` methods.
|
3
16
|
|
@@ -6,6 +6,8 @@ class CreateRailsApiLoggerTable < ActiveRecord::Migration[<%= ActiveRecord::Migr
|
|
6
6
|
t.text :request_body
|
7
7
|
t.text :response_body
|
8
8
|
t.integer :response_code
|
9
|
+
t.timestamp :started_at
|
10
|
+
t.timestamp :ended_at
|
9
11
|
t.references :loggable, index: true, polymorphic: true
|
10
12
|
t.timestamps null: false
|
11
13
|
end
|
@@ -16,6 +18,8 @@ class CreateRailsApiLoggerTable < ActiveRecord::Migration[<%= ActiveRecord::Migr
|
|
16
18
|
t.text :request_body
|
17
19
|
t.text :response_body
|
18
20
|
t.integer :response_code
|
21
|
+
t.timestamp :started_at
|
22
|
+
t.timestamp :ended_at
|
19
23
|
t.references :loggable, index: true, polymorphic: true
|
20
24
|
t.timestamps null: false
|
21
25
|
end
|
data/lib/rails_api_logger.rb
CHANGED
@@ -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.update_columns(response_body: parsed_body(body), response_code: status)
|
20
|
+
@inbound_request_log.update_columns(response_body: parsed_body(body), response_code: status, ended_at: Time.current)
|
21
21
|
end
|
22
22
|
[status, headers, body]
|
23
23
|
end
|
@@ -19,7 +19,7 @@ class RequestLog < ActiveRecord::Base
|
|
19
19
|
rescue JSON::ParserError
|
20
20
|
body
|
21
21
|
end
|
22
|
-
create(path: request.path, request_body: body, method: request.method)
|
22
|
+
create(path: request.path, request_body: body, method: request.method, started_at: Time.current)
|
23
23
|
end
|
24
24
|
|
25
25
|
def formatted_request_body
|
@@ -44,4 +44,9 @@ class RequestLog < ActiveRecord::Base
|
|
44
44
|
rescue
|
45
45
|
body
|
46
46
|
end
|
47
|
+
|
48
|
+
def duration
|
49
|
+
return if started_at.nil? || ended_at.nil?
|
50
|
+
ended_at - started_at
|
51
|
+
end
|
47
52
|
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.4.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-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|