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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0f98d06be4f817e88abd07b2d2a9a80d215dcc8db38ff07817c148712bef613
4
- data.tar.gz: aa421d46edd8af9dc16095d328a13d4a9188a5f31296ecf889a68f8c83bec13f
3
+ metadata.gz: 4b955406c6e0a56ba3242cef72764433a08abc54fa8e0b0241eb85ed3038f5b2
4
+ data.tar.gz: d663a844b8eb827ff0f7693386b7c48e13ab609c1b229978d5626d41b4c4c6f7
5
5
  SHA512:
6
- metadata.gz: ca811de724bab4bc52a5692c111ff709afdee10197ab820dc97b2507c9abded1ca3ea5c52fcd01d367c3e00ad6868a3a47f9aeb74735c9f741ae58a41df3f77e
7
- data.tar.gz: 9cc26c420d60ddd702f2f971edfe244d6e0ec0f6a9c971ef34c83f7adca11375654186cdc3d1d36e02ad3e73bdba9c89a571ab62758585388aa899b4120c9f17
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.1.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.1)
11
- actionpack (= 6.1.4.1)
12
- activesupport (= 6.1.4.1)
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.1)
16
- actionpack (= 6.1.4.1)
17
- activejob (= 6.1.4.1)
18
- activerecord (= 6.1.4.1)
19
- activestorage (= 6.1.4.1)
20
- activesupport (= 6.1.4.1)
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.1)
23
- actionpack (= 6.1.4.1)
24
- actionview (= 6.1.4.1)
25
- activejob (= 6.1.4.1)
26
- activesupport (= 6.1.4.1)
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.1)
30
- actionview (= 6.1.4.1)
31
- activesupport (= 6.1.4.1)
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.1)
37
- actionpack (= 6.1.4.1)
38
- activerecord (= 6.1.4.1)
39
- activestorage (= 6.1.4.1)
40
- activesupport (= 6.1.4.1)
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.1)
43
- activesupport (= 6.1.4.1)
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.1)
49
- activesupport (= 6.1.4.1)
48
+ activejob (6.1.4.6)
49
+ activesupport (= 6.1.4.6)
50
50
  globalid (>= 0.3.6)
51
- activemodel (6.1.4.1)
52
- activesupport (= 6.1.4.1)
53
- activerecord (6.1.4.1)
54
- activemodel (= 6.1.4.1)
55
- activesupport (= 6.1.4.1)
56
- activestorage (6.1.4.1)
57
- actionpack (= 6.1.4.1)
58
- activejob (= 6.1.4.1)
59
- activerecord (= 6.1.4.1)
60
- activesupport (= 6.1.4.1)
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.1)
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.5.2)
73
+ globalid (1.0.0)
74
74
  activesupport (>= 5.0)
75
- i18n (1.8.10)
75
+ i18n (1.10.0)
76
76
  concurrent-ruby (~> 1.0)
77
- loofah (2.12.0)
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
- mini_portile2 (2.6.1)
86
- minitest (5.14.4)
85
+ minitest (5.15.0)
87
86
  nio4r (2.5.8)
88
- nokogiri (1.12.5)
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.1)
96
- actioncable (= 6.1.4.1)
97
- actionmailbox (= 6.1.4.1)
98
- actionmailer (= 6.1.4.1)
99
- actionpack (= 6.1.4.1)
100
- actiontext (= 6.1.4.1)
101
- actionview (= 6.1.4.1)
102
- activejob (= 6.1.4.1)
103
- activemodel (= 6.1.4.1)
104
- activerecord (= 6.1.4.1)
105
- activestorage (= 6.1.4.1)
106
- activesupport (= 6.1.4.1)
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.1)
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.1)
116
- actionpack (= 6.1.4.1)
117
- activesupport (= 6.1.4.1)
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.2.2)
126
- actionpack (>= 4.0)
127
- activesupport (>= 4.0)
123
+ sprockets-rails (3.4.2)
124
+ actionpack (>= 5.2)
125
+ activesupport (>= 5.2)
128
126
  sprockets (>= 3.0.0)
129
- thor (1.1.0)
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.2)
133
+ zeitwerk (2.5.4)
136
134
 
137
135
  PLATFORMS
138
136
  ruby
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017-2021 thomas morgan
1
+ Copyright 2017-2022 thomas morgan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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
- There is no need to use ActiveSupport::TaggedLogging with your logger. Just set the logger directly (if not using the default):
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 6.1 (or later). Anything older is untested. Small patches for older compatibility will be considered.
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
@@ -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.time,
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LogSanity
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
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.1.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: 2021-10-20 00:00:00.000000000 Z
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