effective_logging 3.4.1 → 3.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4453f03163296e4fc99e3b71b9726b5d6a94c111464aabf554789639bd09db42
4
- data.tar.gz: 2dcb56c63e969fa619cedf4a3deb2da0a4204b080f426f077eececabdb0faf94
3
+ metadata.gz: b21edfec95b3f6878025e153f44ebb09bc798ac01d3a117aecfc85b341586078
4
+ data.tar.gz: 8c14b70a56c35b492b19d00fae30b786d871cd3ac95c7c61a34ca133b4533f9d
5
5
  SHA512:
6
- metadata.gz: 60c3450c050554ae8edf1dc069f6bfa44eb8b444f5fe561f4cc3111162b4e60c8b1eb4f50cf6e56c6f48770313b62580081bac0a6852afa4d48b112997b738b1
7
- data.tar.gz: d54d72ea79a1b414444f465f837d0342466b6dba91f7bf6415b0c47c0eed601b14961e7d4d299c26e179a456881efa2d243077cb86ad12fddb93964c8a693215
6
+ metadata.gz: 82a1e987a4642e855ab022c2b81a258fdcf95ad55edea9698e7f2f3766773c0b9f78f8b932c965e64df1c4c8cb6821600dee97063dcfd65c2785f75059e01c52
7
+ data.tar.gz: 33699371abdac488fc0953ba85ab7117076a2b94cb07ce7c7744d86ab90b7d389d1df6a27b33e2920005e3f3406853a3d38a53cd5eb377de090550a0f5e9bfb2
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Automatically log all sent emails, user logins, and page views. This also will log custom events from Ruby and JavaScript.
4
4
 
5
- Logs are stored in a single database table. A Log (one logged event) can have many children Logs, nested to any depth.
5
+ Logs are stored in a single database table.
6
6
 
7
7
  Provides a ruby one-liner to log a message, status, user, associated object and any number of additional details.
8
8
 
@@ -74,18 +74,6 @@ Any other passed options will be serialized and stored as additional details:
74
74
  EffectiveLogger.info 'feedback given', :user => current_user, :feedback => 'your app is great!', :rating => 'good'
75
75
  ```
76
76
 
77
- ### Sub Logs
78
-
79
- Any log can have children logs. This is perfect for long-running tasks where there are multiple sub events:
80
-
81
- ```ruby
82
- log = EffectiveLogger.info('importing important records')
83
-
84
- log.success('record 1 imported', :associated => @record1)
85
- log.error('record 2 failed to import', :associated => @record2)
86
- log.success('record 3 imported', :associated => @record3)
87
- ```
88
-
89
77
  ### Model
90
78
 
91
79
  (optional) Sometimes you'd like to work with the `Effective::Log` relationship directly. Add to your model:
@@ -291,9 +279,6 @@ EffectiveLogger.success('some other event', 'additional', 'information', {subjec
291
279
 
292
280
  The same statuses available to ruby will be available to JavaScript.
293
281
 
294
- Creating child logs via JavaScript is not yet supported.
295
-
296
-
297
282
  ## Admin Screen
298
283
 
299
284
  Visit:
@@ -38,7 +38,7 @@ class EffectiveLogsDatatable < Effective::Datatable
38
38
  # A nil attributes[:log_id] means give me all the top level log entries
39
39
  # If we set a log_id then it's for sub logs
40
40
  collection do
41
- scope = Effective::Log.includes(:user).where(parent_id: attributes[:log_id])
41
+ scope = Effective::Log.deep.all
42
42
 
43
43
  # Older syntax, pass by integer
44
44
  if attributes[:for]
@@ -24,12 +24,6 @@ module EffectiveLoggingHelper
24
24
  render(partial: 'effective/logs/log', locals: { log: log })
25
25
  end
26
26
 
27
- def parents_of_log(log)
28
- parents = [log.parent]
29
- parents << parents.last.parent while(parents.last.try(:parent_id).present?)
30
- parents.compact.reverse
31
- end
32
-
33
27
  # This is called on the Logs#show Admin page, and is intended for override by the application
34
28
  def effective_logging_object_link_to(obj, action = :show)
35
29
  if obj.kind_of?(User)
@@ -4,16 +4,12 @@ module Effective
4
4
  class Log < ActiveRecord::Base
5
5
  self.table_name = EffectiveLogging.logs_table_name.to_s
6
6
 
7
- # Self-Referencing relationship
8
- belongs_to :parent, class_name: 'Effective::Log', counter_cache: true, optional: true
9
- has_many :logs, class_name: 'Effective::Log', foreign_key: :parent_id
10
-
11
7
  belongs_to :user, polymorphic: true, optional: true
12
8
  belongs_to :changes_to, polymorphic: true, optional: true # This is the log_changes to: option
13
9
  belongs_to :associated, polymorphic: true, optional: true
14
10
 
15
11
  effective_resource do
16
- logs_count :integer # Rails Counter Cache
12
+ status :string
17
13
 
18
14
  changes_to_type :string
19
15
  changes_to_id :string
@@ -22,7 +18,6 @@ module Effective
22
18
  associated_id :integer
23
19
  associated_to_s :string
24
20
 
25
- status :string
26
21
  message :text
27
22
  details :text
28
23
 
@@ -48,7 +43,7 @@ module Effective
48
43
  end
49
44
 
50
45
  def log(message, status = EffectiveLogging.statuses.first, options = {})
51
- EffectiveLogger.log(message, status, (options || {}).merge(parent: self))
46
+ EffectiveLogger.log(message, status, options)
52
47
  end
53
48
 
54
49
  def details
@@ -56,15 +51,11 @@ module Effective
56
51
  end
57
52
 
58
53
  def next_log
59
- Log.order(id: :asc).where(parent_id: parent_id).where('id > ?', id).first
54
+ Log.order(id: :asc).where('id > ?', id).first
60
55
  end
61
56
 
62
57
  def prev_log
63
- Log.order(id: :desc).where(parent_id: parent_id).where('id < ?', id).first
64
- end
65
-
66
- def child_logs_datatable
67
- EffectiveLogsDatatable.new(log_id: id)
58
+ Log.order(id: :desc).where('id < ?', id).first
68
59
  end
69
60
 
70
61
  # Dynamically add logging methods based on the defined statuses
@@ -12,10 +12,6 @@ class EffectiveLogger
12
12
  raise ArgumentError.new('Log.log :user => ... argument must be a User object')
13
13
  end
14
14
 
15
- if options[:parent].present? && !options[:parent].kind_of?(Effective::Log)
16
- raise ArgumentError.new('Log.log :parent => ... argument must be an Effective::Log object')
17
- end
18
-
19
15
  if options[:associated].present? && !options[:associated].kind_of?(ActiveRecord::Base)
20
16
  raise ArgumentError.new('Log.log :associated => ... argument must be an ActiveRecord::Base object')
21
17
  end
@@ -34,7 +30,6 @@ class EffectiveLogger
34
30
  user_id: options.delete(:user_id),
35
31
  user_type: options.delete(:user_type),
36
32
  user: options.delete(:user),
37
- parent: options.delete(:parent),
38
33
  associated: options.delete(:associated),
39
34
  associated_to_s: options.delete(:associated_to_s),
40
35
  details: options
@@ -2,9 +2,6 @@
2
2
  .panel-heading.card-header
3
3
  .row
4
4
  .col-md-8
5
- - parents_of_log(log).each do |parent|
6
- = link_to(log.message, request.fullpath.sub('/' + log.to_param, '/' + parent.to_param))
7
- = ' > '
8
5
  %p= log.message.to_s.gsub("\n", '<br>').html_safe
9
6
 
10
7
  .col-md-4.text-right
@@ -31,7 +28,7 @@
31
28
  - if log.user.present?
32
29
  %p
33
30
  %strong User:
34
- = (log.user.to_s.starts_with?('#<User:0x') ? (log.user.email rescue log.user) : log.user)
31
+ = log.user
35
32
 
36
33
  - if log.associated_id.present? && log.associated_type.present? && (log.associated.present? rescue false)
37
34
  %p
@@ -48,8 +45,3 @@
48
45
  .mt-3
49
46
  %strong= "#{key.to_s.titleize}:"
50
47
  = format_log_details_value(log, key)
51
-
52
- - if log.logs.present?
53
- %hr
54
- %p This log contains #{log.logs_count} additional sub entries:
55
- = render_datatable(log.child_logs_datatable)
@@ -1,7 +1,7 @@
1
1
  class CreateEffectiveLogging < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table <%= @logs_table_name %> do |t|
4
- t.integer :parent_id
4
+ t.string :status
5
5
 
6
6
  t.string :user_type
7
7
  t.integer :user_id
@@ -13,21 +13,23 @@ class CreateEffectiveLogging < ActiveRecord::Migration[4.2]
13
13
  t.integer :associated_id
14
14
  t.string :associated_to_s
15
15
 
16
- t.integer :logs_count
17
-
18
16
  t.text :message
19
17
  t.text :details
20
18
 
21
- t.string :status
22
-
23
19
  t.timestamps
24
20
  end
25
21
 
22
+ add_index <%= @logs_table_name %>, :id, order: { id: :desc }
23
+ add_index <%= @logs_table_name %>, :updated_at
26
24
  add_index <%= @logs_table_name %>, :user_id
27
- add_index <%= @logs_table_name %>, :parent_id
28
- add_index <%= @logs_table_name %>, [:associated_type, :associated_id]
29
- add_index <%= @logs_table_name %>, :associated_id
25
+ add_index <%= @logs_table_name %>, :status
30
26
  add_index <%= @logs_table_name %>, :associated_to_s
27
+ add_index <%= @logs_table_name %>, [:associated_type, :associated_id]
28
+ add_index <%= @logs_table_name %>, [:changes_to_type, :changes_to_id]
29
+
30
+ enable_extension('pg_trgm')
31
+ add_index <%= @logs_table_name %>, :message, using: :gin, opclass: :gin_trgm_ops
32
+ add_index <%= @logs_table_name %>, :details, using: :gin, opclass: :gin_trgm_ops
31
33
  end
32
34
 
33
35
  def self.down
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '3.4.1'.freeze
2
+ VERSION = '3.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails