log_sanity 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +64 -66
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/lib/log_sanity/extensions/action_cable_connection.rb +39 -0
- data/lib/log_sanity/formatter.rb +0 -4
- data/lib/log_sanity/log_subscribers/action_cable.rb +30 -0
- data/lib/log_sanity/log_subscribers/action_dispatch.rb +1 -1
- data/lib/log_sanity/log_subscribers/base.rb +9 -0
- data/lib/log_sanity/railtie.rb +14 -0
- data/lib/log_sanity/version.rb +1 -1
- data/lib/log_sanity.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b955406c6e0a56ba3242cef72764433a08abc54fa8e0b0241eb85ed3038f5b2
|
4
|
+
data.tar.gz: d663a844b8eb827ff0f7693386b7c48e13ab609c1b229978d5626d41b4c4c6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf2265262ef180c669376798887e66e92176e07fcc725f8ccfc6bdf0e642c450363d0214f0aed8519c9e1ac7369ac117e6f8ceb2f2d88cdf3da9d12bc17616b
|
7
|
+
data.tar.gz: d1eaf205cd088590de19326404fc59eb076a8cd6d9d8c3dc777a1fa681d017d213cc5796c43f88efba8a8ebc52e875bf39fd5e63da3d72ffdb82111d9c23c2a2
|
data/Gemfile.lock
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
log_sanity (1.
|
4
|
+
log_sanity (1.2.0)
|
5
5
|
rails (>= 5.2, < 7.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (6.1.4.
|
11
|
-
actionpack (= 6.1.4.
|
12
|
-
activesupport (= 6.1.4.
|
10
|
+
actioncable (6.1.4.6)
|
11
|
+
actionpack (= 6.1.4.6)
|
12
|
+
activesupport (= 6.1.4.6)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
actionmailbox (6.1.4.
|
16
|
-
actionpack (= 6.1.4.
|
17
|
-
activejob (= 6.1.4.
|
18
|
-
activerecord (= 6.1.4.
|
19
|
-
activestorage (= 6.1.4.
|
20
|
-
activesupport (= 6.1.4.
|
15
|
+
actionmailbox (6.1.4.6)
|
16
|
+
actionpack (= 6.1.4.6)
|
17
|
+
activejob (= 6.1.4.6)
|
18
|
+
activerecord (= 6.1.4.6)
|
19
|
+
activestorage (= 6.1.4.6)
|
20
|
+
activesupport (= 6.1.4.6)
|
21
21
|
mail (>= 2.7.1)
|
22
|
-
actionmailer (6.1.4.
|
23
|
-
actionpack (= 6.1.4.
|
24
|
-
actionview (= 6.1.4.
|
25
|
-
activejob (= 6.1.4.
|
26
|
-
activesupport (= 6.1.4.
|
22
|
+
actionmailer (6.1.4.6)
|
23
|
+
actionpack (= 6.1.4.6)
|
24
|
+
actionview (= 6.1.4.6)
|
25
|
+
activejob (= 6.1.4.6)
|
26
|
+
activesupport (= 6.1.4.6)
|
27
27
|
mail (~> 2.5, >= 2.5.4)
|
28
28
|
rails-dom-testing (~> 2.0)
|
29
|
-
actionpack (6.1.4.
|
30
|
-
actionview (= 6.1.4.
|
31
|
-
activesupport (= 6.1.4.
|
29
|
+
actionpack (6.1.4.6)
|
30
|
+
actionview (= 6.1.4.6)
|
31
|
+
activesupport (= 6.1.4.6)
|
32
32
|
rack (~> 2.0, >= 2.0.9)
|
33
33
|
rack-test (>= 0.6.3)
|
34
34
|
rails-dom-testing (~> 2.0)
|
35
35
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
-
actiontext (6.1.4.
|
37
|
-
actionpack (= 6.1.4.
|
38
|
-
activerecord (= 6.1.4.
|
39
|
-
activestorage (= 6.1.4.
|
40
|
-
activesupport (= 6.1.4.
|
36
|
+
actiontext (6.1.4.6)
|
37
|
+
actionpack (= 6.1.4.6)
|
38
|
+
activerecord (= 6.1.4.6)
|
39
|
+
activestorage (= 6.1.4.6)
|
40
|
+
activesupport (= 6.1.4.6)
|
41
41
|
nokogiri (>= 1.8.5)
|
42
|
-
actionview (6.1.4.
|
43
|
-
activesupport (= 6.1.4.
|
42
|
+
actionview (6.1.4.6)
|
43
|
+
activesupport (= 6.1.4.6)
|
44
44
|
builder (~> 3.1)
|
45
45
|
erubi (~> 1.4)
|
46
46
|
rails-dom-testing (~> 2.0)
|
47
47
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
-
activejob (6.1.4.
|
49
|
-
activesupport (= 6.1.4.
|
48
|
+
activejob (6.1.4.6)
|
49
|
+
activesupport (= 6.1.4.6)
|
50
50
|
globalid (>= 0.3.6)
|
51
|
-
activemodel (6.1.4.
|
52
|
-
activesupport (= 6.1.4.
|
53
|
-
activerecord (6.1.4.
|
54
|
-
activemodel (= 6.1.4.
|
55
|
-
activesupport (= 6.1.4.
|
56
|
-
activestorage (6.1.4.
|
57
|
-
actionpack (= 6.1.4.
|
58
|
-
activejob (= 6.1.4.
|
59
|
-
activerecord (= 6.1.4.
|
60
|
-
activesupport (= 6.1.4.
|
51
|
+
activemodel (6.1.4.6)
|
52
|
+
activesupport (= 6.1.4.6)
|
53
|
+
activerecord (6.1.4.6)
|
54
|
+
activemodel (= 6.1.4.6)
|
55
|
+
activesupport (= 6.1.4.6)
|
56
|
+
activestorage (6.1.4.6)
|
57
|
+
actionpack (= 6.1.4.6)
|
58
|
+
activejob (= 6.1.4.6)
|
59
|
+
activerecord (= 6.1.4.6)
|
60
|
+
activesupport (= 6.1.4.6)
|
61
61
|
marcel (~> 1.0.0)
|
62
62
|
mini_mime (>= 1.1.0)
|
63
|
-
activesupport (6.1.4.
|
63
|
+
activesupport (6.1.4.6)
|
64
64
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
65
|
i18n (>= 1.6, < 2)
|
66
66
|
minitest (>= 5.1)
|
@@ -70,11 +70,11 @@ GEM
|
|
70
70
|
concurrent-ruby (1.1.9)
|
71
71
|
crass (1.0.6)
|
72
72
|
erubi (1.10.0)
|
73
|
-
globalid (0.
|
73
|
+
globalid (1.0.0)
|
74
74
|
activesupport (>= 5.0)
|
75
|
-
i18n (1.
|
75
|
+
i18n (1.10.0)
|
76
76
|
concurrent-ruby (~> 1.0)
|
77
|
-
loofah (2.
|
77
|
+
loofah (2.14.0)
|
78
78
|
crass (~> 1.0.2)
|
79
79
|
nokogiri (>= 1.5.9)
|
80
80
|
mail (2.7.1)
|
@@ -82,39 +82,37 @@ GEM
|
|
82
82
|
marcel (1.0.2)
|
83
83
|
method_source (1.0.0)
|
84
84
|
mini_mime (1.1.2)
|
85
|
-
|
86
|
-
minitest (5.14.4)
|
85
|
+
minitest (5.15.0)
|
87
86
|
nio4r (2.5.8)
|
88
|
-
nokogiri (1.
|
89
|
-
mini_portile2 (~> 2.6.1)
|
87
|
+
nokogiri (1.13.3-x86_64-darwin)
|
90
88
|
racc (~> 1.4)
|
91
89
|
racc (1.6.0)
|
92
90
|
rack (2.2.3)
|
93
91
|
rack-test (1.1.0)
|
94
92
|
rack (>= 1.0, < 3)
|
95
|
-
rails (6.1.4.
|
96
|
-
actioncable (= 6.1.4.
|
97
|
-
actionmailbox (= 6.1.4.
|
98
|
-
actionmailer (= 6.1.4.
|
99
|
-
actionpack (= 6.1.4.
|
100
|
-
actiontext (= 6.1.4.
|
101
|
-
actionview (= 6.1.4.
|
102
|
-
activejob (= 6.1.4.
|
103
|
-
activemodel (= 6.1.4.
|
104
|
-
activerecord (= 6.1.4.
|
105
|
-
activestorage (= 6.1.4.
|
106
|
-
activesupport (= 6.1.4.
|
93
|
+
rails (6.1.4.6)
|
94
|
+
actioncable (= 6.1.4.6)
|
95
|
+
actionmailbox (= 6.1.4.6)
|
96
|
+
actionmailer (= 6.1.4.6)
|
97
|
+
actionpack (= 6.1.4.6)
|
98
|
+
actiontext (= 6.1.4.6)
|
99
|
+
actionview (= 6.1.4.6)
|
100
|
+
activejob (= 6.1.4.6)
|
101
|
+
activemodel (= 6.1.4.6)
|
102
|
+
activerecord (= 6.1.4.6)
|
103
|
+
activestorage (= 6.1.4.6)
|
104
|
+
activesupport (= 6.1.4.6)
|
107
105
|
bundler (>= 1.15.0)
|
108
|
-
railties (= 6.1.4.
|
106
|
+
railties (= 6.1.4.6)
|
109
107
|
sprockets-rails (>= 2.0.0)
|
110
108
|
rails-dom-testing (2.0.3)
|
111
109
|
activesupport (>= 4.2.0)
|
112
110
|
nokogiri (>= 1.6)
|
113
111
|
rails-html-sanitizer (1.4.2)
|
114
112
|
loofah (~> 2.3)
|
115
|
-
railties (6.1.4.
|
116
|
-
actionpack (= 6.1.4.
|
117
|
-
activesupport (= 6.1.4.
|
113
|
+
railties (6.1.4.6)
|
114
|
+
actionpack (= 6.1.4.6)
|
115
|
+
activesupport (= 6.1.4.6)
|
118
116
|
method_source
|
119
117
|
rake (>= 0.13)
|
120
118
|
thor (~> 1.0)
|
@@ -122,17 +120,17 @@ GEM
|
|
122
120
|
sprockets (4.0.2)
|
123
121
|
concurrent-ruby (~> 1.0)
|
124
122
|
rack (> 1, < 3)
|
125
|
-
sprockets-rails (3.
|
126
|
-
actionpack (>=
|
127
|
-
activesupport (>=
|
123
|
+
sprockets-rails (3.4.2)
|
124
|
+
actionpack (>= 5.2)
|
125
|
+
activesupport (>= 5.2)
|
128
126
|
sprockets (>= 3.0.0)
|
129
|
-
thor (1.1
|
127
|
+
thor (1.2.1)
|
130
128
|
tzinfo (2.0.4)
|
131
129
|
concurrent-ruby (~> 1.0)
|
132
130
|
websocket-driver (0.7.5)
|
133
131
|
websocket-extensions (>= 0.1.0)
|
134
132
|
websocket-extensions (0.1.5)
|
135
|
-
zeitwerk (2.4
|
133
|
+
zeitwerk (2.5.4)
|
136
134
|
|
137
135
|
PLATFORMS
|
138
136
|
ruby
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -143,7 +143,7 @@ LogSanity takes these and adds them to the default request log entry (but _not_
|
|
143
143
|
|
144
144
|
LogSanity is intended for production use at log_level info. At level debug, some logs are simply turned off. Others may continue to output as normal strings (such as ActiveRecord).
|
145
145
|
|
146
|
-
|
146
|
+
If not using tags, there is no need to use ActiveSupport::TaggedLogging with your logger. Just set the logger directly (if not using the default):
|
147
147
|
```
|
148
148
|
config.logger = ActiveSupport::Logger.new(STDOUT)
|
149
149
|
```
|
@@ -172,7 +172,7 @@ There are still some things that could be handled better (such as multi-line str
|
|
172
172
|
|
173
173
|
Pull requests are welcomed and encouraged. The only goal is to avoid making things unnecessarily complex.
|
174
174
|
|
175
|
-
Tested on Rails 5.2 through
|
175
|
+
Tested on Rails 5.2 through 7.0 (or later). Anything older is untested. Small patches for older compatibility will be considered.
|
176
176
|
|
177
177
|
License: MIT
|
178
178
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module LogSanity
|
2
|
+
module Extensions
|
3
|
+
module ActionCableConnection
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def close(reason: nil, **args)
|
7
|
+
@close_reason = reason
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def process
|
12
|
+
payload = { request: request }
|
13
|
+
ActiveSupport::Notifications.instrument("process.action_cable", payload) do
|
14
|
+
status, _, _ = response = super
|
15
|
+
payload[:status] = status==-1 ? 101 : status
|
16
|
+
response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def reject_unauthorized_connection
|
21
|
+
logger.instance_variable_get(:@logger).silence(Logger::FATAL) do
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def on_close(reason, code)
|
27
|
+
payload = {
|
28
|
+
connection_sec: Time.now - @started_at,
|
29
|
+
request: request
|
30
|
+
}
|
31
|
+
payload[:reason] = @close_reason if @close_reason
|
32
|
+
ActiveSupport::Notifications.instrument("on_close.action_cable", payload) do
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/log_sanity/formatter.rb
CHANGED
@@ -26,10 +26,6 @@ module LogSanity
|
|
26
26
|
else
|
27
27
|
msg = {'at' => timestamp, 'object' => msg.inspect}
|
28
28
|
end
|
29
|
-
if msg['at'].is_a? Float
|
30
|
-
monot = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
31
|
-
msg['at'] = Time.now - (monot - msg['at'])
|
32
|
-
end
|
33
29
|
msg['at'] = msg['at'].utc
|
34
30
|
"#{msg.to_json}\n"
|
35
31
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LogSanity
|
2
|
+
module LogSubscriber
|
3
|
+
class ActionCable < Base
|
4
|
+
|
5
|
+
def process(event)
|
6
|
+
payload = event.payload
|
7
|
+
log 'event', 'ws_connect'
|
8
|
+
log 'status', payload[:status]
|
9
|
+
# logged by the actiondispatch subscriber
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_close(event)
|
13
|
+
payload = event.payload
|
14
|
+
request = payload[:request]
|
15
|
+
info do
|
16
|
+
e = {
|
17
|
+
'at' => Time.now,
|
18
|
+
'event' => 'ws_disconnect',
|
19
|
+
'ip' => request.remote_ip,
|
20
|
+
'rq' => request.uuid,
|
21
|
+
'duration' => {'socket' => "#{payload[:connection_sec].round}s"}
|
22
|
+
}
|
23
|
+
e['reason'] = payload[:reason] if payload[:reason]
|
24
|
+
e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -11,7 +11,7 @@ module LogSanity
|
|
11
11
|
response = payload[:response]
|
12
12
|
method = payload[:method] || (request.request_method rescue nil) || 'UNKNOWN'
|
13
13
|
f2 = {
|
14
|
-
'at' => event
|
14
|
+
'at' => event_start(event),
|
15
15
|
'event' => "#{request.scheme}_#{method.downcase}",
|
16
16
|
'ip' => request.remote_ip,
|
17
17
|
'rq' => request.uuid,
|
@@ -5,6 +5,15 @@ module LogSanity
|
|
5
5
|
private
|
6
6
|
delegate :fields, :log, to: LogSanity
|
7
7
|
|
8
|
+
def event_start(event)
|
9
|
+
if event.time.is_a? Float
|
10
|
+
# convert event's monotonic start .time to a Time
|
11
|
+
Time.current - event.duration/1000.0
|
12
|
+
else
|
13
|
+
event.time
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
end
|
9
18
|
end
|
10
19
|
end
|
data/lib/log_sanity/railtie.rb
CHANGED
@@ -41,11 +41,25 @@ module LogSanity
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
if defined?(ActiveRecord)
|
44
|
+
# require 'active_record/log_subscriber'
|
45
|
+
# ActiveRecord::LogSubscriber.detach_from :active_record
|
46
|
+
# this turns off measurements too
|
44
47
|
if ActiveRecord::Base.logger.debug?
|
45
48
|
Rails.logger.info '[LogSanity] ActiveRecord::Base.logger in debug mode and will still log queries'
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
52
|
+
ActiveSupport.on_load(:action_cable) do
|
53
|
+
orig_logger = logger || Rails.logger
|
54
|
+
self.logger = orig_logger.clone.tap do |l|
|
55
|
+
l.level = Logger::WARN
|
56
|
+
end
|
57
|
+
end
|
58
|
+
ActiveSupport.on_load(:action_cable_connection) do
|
59
|
+
prepend LogSanity::Extensions::ActionCableConnection
|
60
|
+
end
|
61
|
+
|
62
|
+
LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
|
49
63
|
LogSanity::LogSubscriber::ActionController.attach_to :action_controller
|
50
64
|
LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
|
51
65
|
LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
|
data/lib/log_sanity/version.rb
CHANGED
data/lib/log_sanity.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
%w( formatter
|
2
2
|
railtie
|
3
3
|
log_subscribers/base
|
4
|
+
log_subscribers/action_cable
|
4
5
|
log_subscribers/action_controller
|
5
6
|
log_subscribers/action_dispatch
|
6
7
|
log_subscribers/action_mailer
|
7
8
|
log_subscribers/active_job
|
8
9
|
middleware/request_logger
|
9
10
|
middleware/routing_error_catcher
|
11
|
+
extensions/action_cable_connection
|
10
12
|
extensions/action_controller_helper
|
11
13
|
extensions/active_support_subscriber
|
12
14
|
).each do |fn|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_sanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -45,9 +45,11 @@ files:
|
|
45
45
|
- README.md
|
46
46
|
- Rakefile
|
47
47
|
- lib/log_sanity.rb
|
48
|
+
- lib/log_sanity/extensions/action_cable_connection.rb
|
48
49
|
- lib/log_sanity/extensions/action_controller_helper.rb
|
49
50
|
- lib/log_sanity/extensions/active_support_subscriber.rb
|
50
51
|
- lib/log_sanity/formatter.rb
|
52
|
+
- lib/log_sanity/log_subscribers/action_cable.rb
|
51
53
|
- lib/log_sanity/log_subscribers/action_controller.rb
|
52
54
|
- lib/log_sanity/log_subscribers/action_dispatch.rb
|
53
55
|
- lib/log_sanity/log_subscribers/action_mailer.rb
|