audit-log 0.3.2 → 1.0.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: f260e9ba5935c19f8abc860626f55bad7143114a4d6dccc91426f1026ae5b852
4
- data.tar.gz: db2c855ffaa981972cec024d3acfe551b483a6f6c60c2b3c2714ba2c21c73dee
3
+ metadata.gz: cd049092e7b9e427a66e776f4248c42a74b19fb667a12fec8aa5ecf9abaf08f3
4
+ data.tar.gz: 2d7e6e61ddf78747fbf9dbb1b2b427c16fa6c0015405eaf3222e23839afdf691
5
5
  SHA512:
6
- metadata.gz: ef5227fe304be06dc55e5465c2e74c37bcb76acc475d839c3844574bccde9081a0cf83bea763aa91062faaa52e718598935aa3a2d6c5ccd85ede9f017a771843
7
- data.tar.gz: f4cb4ee5dd6d482687c8fbc788f54a4c269a4d8eb50559119e65506f8df5cc439d3246bfae9e8e9456c47833cfc787dadaee3db076ca0aa274fdfd494dd706a0
6
+ metadata.gz: a3c21ee0a6658f309188e1fffb17c906cf0005eb0c67ed337e65f6c0ba901e17ec1238e49e796abb7bb173e70dd61385b28d7af7fcc64d8fefd8cd06c829fa82
7
+ data.tar.gz: 3faacb77c43e1af56395c4aa515c67e536a1a96c719baa313051bd6995aa17d949c67454a0234b3bbf35329fa0b7eecc2a29b4d13bbc0105773f2dbfef9da755
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # AuditLog
2
2
 
3
- Trail audit logs (Operation logs) into the database for user behaviors, including a web UI to query logs.
3
+ Trail audit logs (Operation logs) into the database for user behaviors, including a Web UI to query logs.
4
4
 
5
5
  [![Build Status](https://travis-ci.org/rails-engine/audit-log.svg?branch=master)](https://travis-ci.org/rails-engine/audit-log)
6
6
 
7
+ > We used audit-log in our production environment more than 1 year, until now (2020.5.21), it's inserted about **20 million** log in our system.
8
+
7
9
  ## Demo UI
8
10
 
9
11
  Audit log list:
data/lib/audit-log.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './audit-log/version'
2
4
  require_relative './audit-log/configuration'
3
5
  require_relative './audit-log/model'
6
+ require_relative './audit-log/log_subscriber'
4
7
  require_relative './audit-log/engine'
5
8
  require 'kaminari'
6
9
 
@@ -24,31 +27,35 @@ module AuditLog
24
27
  #
25
28
  # AuditLog.audit!(:edit_account, @account, payload: account_params, user: current_user)
26
29
  def audit!(action, record = nil, payload: nil, user: nil, request: nil)
27
- request_info = {}
28
- if request
29
- request_info = {
30
- request_id: request.request_id,
31
- ip: request.remote_ip,
32
- url: request.url,
33
- user_agent: request.user_agent
34
- }
35
- end
30
+ ActiveSupport::Notifications.instrument('audit.audit_log', action: action) do
31
+ request_info = {}
32
+ if request
33
+ request_info = {
34
+ request_id: request.request_id,
35
+ ip: request.remote_ip,
36
+ url: request.url,
37
+ user_agent: request.user_agent
38
+ }
39
+ end
36
40
 
37
- # Set nil if record is a new_record, do this for avoid create record.
38
- record = nil if record&.new_record?
41
+ # Set nil if record is a new_record, do this for avoid create record.
42
+ record = nil if record&.new_record?
39
43
 
40
- AuditLog::Log.create!(
41
- action: action,
42
- record: record,
43
- payload: (payload || {}).to_h.deep_stringify_keys,
44
- user: user,
45
- request: request_info.deep_stringify_keys
46
- )
44
+ Rails.logger.silence do
45
+ AuditLog::Log.create!(
46
+ action: action,
47
+ record: record,
48
+ payload: (payload || {}).to_h.deep_stringify_keys,
49
+ user: user,
50
+ request: request_info.deep_stringify_keys
51
+ )
52
+ end
53
+ end
47
54
  end
48
55
 
49
56
  # Get I18n action name options for select
50
57
  def action_options
51
- I18n.t("audit_log.action").map { |k, v| [v, k.to_s] }
58
+ I18n.t('audit_log.action').map { |k, v| [v, k.to_s] }
52
59
  end
53
60
  end
54
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './controller_helper'
2
4
 
3
5
  module AuditLog
@@ -8,8 +10,10 @@ module AuditLog
8
10
  prepend AuditLog::ControllerHelper
9
11
  end
10
12
 
11
- initializer "audit-log.assets.precompile", group: :all do |app|
12
- app.config.assets.precompile += %w( audit-log/application.css )
13
+ AuditLog::LogSubscriber.attach_to :audit_log
14
+
15
+ initializer 'audit-log.assets.precompile', group: :all do |app|
16
+ app.config.assets.precompile += %w[audit-log/application.css]
13
17
  end
14
18
  end
15
19
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuditLog
4
+ class LogSubscriber < ActiveSupport::LogSubscriber
5
+ # ActiveSupport::Notifications.instrument('audit.audit_log', action: action)
6
+ def audit(event)
7
+ prefix = color('AuditLog', CYAN)
8
+ action = color(event.payload[:action], BLUE)
9
+ debug " #{prefix} #{action} (#{event.duration.round(1)}ms)"
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuditLog
4
- VERSION = '0.3.2'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audit-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-23 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari
@@ -77,6 +77,7 @@ files:
77
77
  - lib/audit-log/configuration.rb
78
78
  - lib/audit-log/controller_helper.rb
79
79
  - lib/audit-log/engine.rb
80
+ - lib/audit-log/log_subscriber.rb
80
81
  - lib/audit-log/model.rb
81
82
  - lib/audit-log/version.rb
82
83
  - lib/generators/audit_log/install_generator.rb