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 +4 -4
- data/README.md +3 -1
- data/lib/audit-log.rb +26 -19
- data/lib/audit-log/engine.rb +6 -2
- data/lib/audit-log/log_subscriber.rb +12 -0
- data/lib/audit-log/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd049092e7b9e427a66e776f4248c42a74b19fb667a12fec8aa5ecf9abaf08f3
|
4
|
+
data.tar.gz: 2d7e6e61ddf78747fbf9dbb1b2b427c16fa6c0015405eaf3222e23839afdf691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
3
|
+
Trail audit logs (Operation logs) into the database for user behaviors, including a Web UI to query logs.
|
4
4
|
|
5
5
|
[](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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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(
|
58
|
+
I18n.t('audit_log.action').map { |k, v| [v, k.to_s] }
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
data/lib/audit-log/engine.rb
CHANGED
@@ -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
|
-
|
12
|
-
|
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
|
data/lib/audit-log/version.rb
CHANGED
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.
|
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:
|
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
|