rails_api_logger 0.3.0 → 0.4.0

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: 1f13c4887a4835f4654755c70748676106fd20649619fad63084f6a0fc2c9787
4
- data.tar.gz: 42309cf04f2727b76bb88818e3c694cf5ba80d63f0535b4223c2a4a29d93db99
3
+ metadata.gz: 6a4cfc6305629f5d93ede15587bb8abc1f9218fa0f07fab94f3e8a9547c11609
4
+ data.tar.gz: f1c3dd646b07d8774833769d9d8417b32dae2a3ab6a1aa1297b041b6fbdf552f
5
5
  SHA512:
6
- metadata.gz: e7b7c914d762daeba5c54d617f4d6802d506b72db0023775ad3548820327e2199608a40af3534b28224744ebcfcd9e8944d2cb313dc9fc30440e8bcfc377711a
7
- data.tar.gz: 16dbc39a87e88cbed4eadc2dccd24eac17140c349addd336e32f6c55b895316752f07bbc49c7b2b953cbfc3bbb854cf8126b786f0b4298a7df4f941de9b22d81
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
@@ -21,6 +21,7 @@ module RailsApiLogger
21
21
  log.response_body = {error: e.message}
22
22
  raise
23
23
  ensure
24
+ log.ended_at = Time.current
24
25
  log.save!
25
26
  end
26
27
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsApiLogger
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  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.3.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-05-27 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties