log_sanity 1.3.2 → 2.0.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: 1e14932031fa3c9e9fbc8291f47c77a35218cdc84796da7093514dcfb4b01e3e
4
- data.tar.gz: 2ca40f03ffce94c6ef444e6501ed042f019005a5befa33e86190c3ad0f36809b
3
+ metadata.gz: 3a0edb320430f364dcba88e455a88eb3cea47cc2630b691457e70b9727001a70
4
+ data.tar.gz: db6591479d06b2b435bbd8992f3abf28e47dc15414bc87ccf6d7d3f0864e998d
5
5
  SHA512:
6
- metadata.gz: e1e2e9ae966e33a14056618992f00804885d1f17926761a8f75852dddf0dc9421e4917142d2bc389fd0d599c58b170bf2777581484b436b31691f326a45a0462
7
- data.tar.gz: e9da30d7b72803e27234d8e396822ca610b8b976b5b371746594c54ef293baeceaba29f7e6dd6375a0cfdaa806a552393c92c2118b6290ad95b3415c33c0a1e0
6
+ metadata.gz: ef54dae274716b9d5c2bc180747b44cda69892a42e1c7addb7c8bee1275869ec9d4db97e88a5c0428eb15562bc49b1611c94160031fae6022c88c49902bda53f
7
+ data.tar.gz: '0191a93198383de05c394f38d3cf4f046d0189d3b5ef78da900fd237353aab913bff98665fc606225a0179e187cd063e87e1947b617a08beebeead11d77cf8d6'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ #### 2.0.0
2
+
3
+ - (Breaking) Require Rails 7.1
4
+ For Rails 5.2, 6.x, and 7.0, use log_sanity 1.x
5
+ - (Potentially breaking) Remove RoutingErrorCatcher middleware
6
+ Shouldn't break unless directly referenced during app's middleware setup
7
+ Mostly not needed on Rails 7.1, but for an alternative, see [rails-hush](https://github.com/zarqman/rails-hush) gem
8
+ - Handle new events and updated payloads for Rails 7.1
9
+ - Use updated instrumentation API in request_logger
10
+ - Refactor initializer to use on_load
11
+
1
12
  #### 1.3.2
2
13
 
3
14
  - Fix logging on Rails 7.1 due to default use of BroadcastLogger
data/Gemfile.lock CHANGED
@@ -1,86 +1,103 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- log_sanity (1.3.2)
5
- rails (>= 5.2, < 7.2)
4
+ log_sanity (2.0.0)
5
+ rails (>= 7.1, < 7.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (7.0.5)
11
- actionpack (= 7.0.5)
12
- activesupport (= 7.0.5)
10
+ actioncable (7.1.0)
11
+ actionpack (= 7.1.0)
12
+ activesupport (= 7.1.0)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (7.0.5)
16
- actionpack (= 7.0.5)
17
- activejob (= 7.0.5)
18
- activerecord (= 7.0.5)
19
- activestorage (= 7.0.5)
20
- activesupport (= 7.0.5)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.1.0)
17
+ actionpack (= 7.1.0)
18
+ activejob (= 7.1.0)
19
+ activerecord (= 7.1.0)
20
+ activestorage (= 7.1.0)
21
+ activesupport (= 7.1.0)
21
22
  mail (>= 2.7.1)
22
23
  net-imap
23
24
  net-pop
24
25
  net-smtp
25
- actionmailer (7.0.5)
26
- actionpack (= 7.0.5)
27
- actionview (= 7.0.5)
28
- activejob (= 7.0.5)
29
- activesupport (= 7.0.5)
26
+ actionmailer (7.1.0)
27
+ actionpack (= 7.1.0)
28
+ actionview (= 7.1.0)
29
+ activejob (= 7.1.0)
30
+ activesupport (= 7.1.0)
30
31
  mail (~> 2.5, >= 2.5.4)
31
32
  net-imap
32
33
  net-pop
33
34
  net-smtp
34
- rails-dom-testing (~> 2.0)
35
- actionpack (7.0.5)
36
- actionview (= 7.0.5)
37
- activesupport (= 7.0.5)
38
- rack (~> 2.0, >= 2.2.4)
35
+ rails-dom-testing (~> 2.2)
36
+ actionpack (7.1.0)
37
+ actionview (= 7.1.0)
38
+ activesupport (= 7.1.0)
39
+ nokogiri (>= 1.8.5)
40
+ rack (>= 2.2.4)
41
+ rack-session (>= 1.0.1)
39
42
  rack-test (>= 0.6.3)
40
- rails-dom-testing (~> 2.0)
41
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
42
- actiontext (7.0.5)
43
- actionpack (= 7.0.5)
44
- activerecord (= 7.0.5)
45
- activestorage (= 7.0.5)
46
- activesupport (= 7.0.5)
43
+ rails-dom-testing (~> 2.2)
44
+ rails-html-sanitizer (~> 1.6)
45
+ actiontext (7.1.0)
46
+ actionpack (= 7.1.0)
47
+ activerecord (= 7.1.0)
48
+ activestorage (= 7.1.0)
49
+ activesupport (= 7.1.0)
47
50
  globalid (>= 0.6.0)
48
51
  nokogiri (>= 1.8.5)
49
- actionview (7.0.5)
50
- activesupport (= 7.0.5)
52
+ actionview (7.1.0)
53
+ activesupport (= 7.1.0)
51
54
  builder (~> 3.1)
52
- erubi (~> 1.4)
53
- rails-dom-testing (~> 2.0)
54
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
- activejob (7.0.5)
56
- activesupport (= 7.0.5)
55
+ erubi (~> 1.11)
56
+ rails-dom-testing (~> 2.2)
57
+ rails-html-sanitizer (~> 1.6)
58
+ activejob (7.1.0)
59
+ activesupport (= 7.1.0)
57
60
  globalid (>= 0.3.6)
58
- activemodel (7.0.5)
59
- activesupport (= 7.0.5)
60
- activerecord (7.0.5)
61
- activemodel (= 7.0.5)
62
- activesupport (= 7.0.5)
63
- activestorage (7.0.5)
64
- actionpack (= 7.0.5)
65
- activejob (= 7.0.5)
66
- activerecord (= 7.0.5)
67
- activesupport (= 7.0.5)
61
+ activemodel (7.1.0)
62
+ activesupport (= 7.1.0)
63
+ activerecord (7.1.0)
64
+ activemodel (= 7.1.0)
65
+ activesupport (= 7.1.0)
66
+ timeout (>= 0.4.0)
67
+ activestorage (7.1.0)
68
+ actionpack (= 7.1.0)
69
+ activejob (= 7.1.0)
70
+ activerecord (= 7.1.0)
71
+ activesupport (= 7.1.0)
68
72
  marcel (~> 1.0)
69
- mini_mime (>= 1.1.0)
70
- activesupport (7.0.5)
73
+ activesupport (7.1.0)
74
+ base64
75
+ bigdecimal
71
76
  concurrent-ruby (~> 1.0, >= 1.0.2)
77
+ connection_pool (>= 2.2.5)
78
+ drb
72
79
  i18n (>= 1.6, < 2)
73
80
  minitest (>= 5.1)
81
+ mutex_m
74
82
  tzinfo (~> 2.0)
83
+ base64 (0.1.1)
84
+ bigdecimal (3.1.4)
75
85
  builder (3.2.4)
76
86
  concurrent-ruby (1.2.2)
87
+ connection_pool (2.4.1)
77
88
  crass (1.0.6)
78
89
  date (3.3.3)
90
+ drb (2.1.1)
91
+ ruby2_keywords
79
92
  erubi (1.12.0)
80
- globalid (1.1.0)
81
- activesupport (>= 5.0)
82
- i18n (1.13.0)
93
+ globalid (1.2.1)
94
+ activesupport (>= 6.1)
95
+ i18n (1.14.1)
83
96
  concurrent-ruby (~> 1.0)
97
+ io-console (0.6.0)
98
+ irb (1.8.1)
99
+ rdoc
100
+ reline (>= 0.3.8)
84
101
  loofah (2.21.3)
85
102
  crass (~> 1.0.2)
86
103
  nokogiri (>= 1.12.0)
@@ -90,65 +107,84 @@ GEM
90
107
  net-pop
91
108
  net-smtp
92
109
  marcel (1.0.2)
93
- method_source (1.0.0)
94
- mini_mime (1.1.2)
95
- minitest (5.18.0)
96
- net-imap (0.3.4)
110
+ mini_mime (1.1.5)
111
+ minitest (5.20.0)
112
+ mutex_m (0.1.2)
113
+ net-imap (0.4.1)
97
114
  date
98
115
  net-protocol
99
116
  net-pop (0.1.2)
100
117
  net-protocol
101
118
  net-protocol (0.2.1)
102
119
  timeout
103
- net-smtp (0.3.3)
120
+ net-smtp (0.4.0)
104
121
  net-protocol
105
122
  nio4r (2.5.9)
106
- nokogiri (1.15.2-arm64-darwin)
123
+ nokogiri (1.15.4-arm64-darwin)
124
+ racc (~> 1.4)
125
+ nokogiri (1.15.4-x86_64-darwin)
126
+ racc (~> 1.4)
127
+ nokogiri (1.15.4-x86_64-linux)
107
128
  racc (~> 1.4)
108
- racc (1.6.2)
109
- rack (2.2.7)
129
+ psych (5.1.0)
130
+ stringio
131
+ racc (1.7.1)
132
+ rack (3.0.8)
133
+ rack-session (2.0.0)
134
+ rack (>= 3.0.0)
110
135
  rack-test (2.1.0)
111
136
  rack (>= 1.3)
112
- rails (7.0.5)
113
- actioncable (= 7.0.5)
114
- actionmailbox (= 7.0.5)
115
- actionmailer (= 7.0.5)
116
- actionpack (= 7.0.5)
117
- actiontext (= 7.0.5)
118
- actionview (= 7.0.5)
119
- activejob (= 7.0.5)
120
- activemodel (= 7.0.5)
121
- activerecord (= 7.0.5)
122
- activestorage (= 7.0.5)
123
- activesupport (= 7.0.5)
137
+ rackup (2.1.0)
138
+ rack (>= 3)
139
+ webrick (~> 1.8)
140
+ rails (7.1.0)
141
+ actioncable (= 7.1.0)
142
+ actionmailbox (= 7.1.0)
143
+ actionmailer (= 7.1.0)
144
+ actionpack (= 7.1.0)
145
+ actiontext (= 7.1.0)
146
+ actionview (= 7.1.0)
147
+ activejob (= 7.1.0)
148
+ activemodel (= 7.1.0)
149
+ activerecord (= 7.1.0)
150
+ activestorage (= 7.1.0)
151
+ activesupport (= 7.1.0)
124
152
  bundler (>= 1.15.0)
125
- railties (= 7.0.5)
126
- rails-dom-testing (2.0.3)
127
- activesupport (>= 4.2.0)
153
+ railties (= 7.1.0)
154
+ rails-dom-testing (2.2.0)
155
+ activesupport (>= 5.0.0)
156
+ minitest
128
157
  nokogiri (>= 1.6)
129
158
  rails-html-sanitizer (1.6.0)
130
159
  loofah (~> 2.21)
131
160
  nokogiri (~> 1.14)
132
- railties (7.0.5)
133
- actionpack (= 7.0.5)
134
- activesupport (= 7.0.5)
135
- method_source
161
+ railties (7.1.0)
162
+ actionpack (= 7.1.0)
163
+ activesupport (= 7.1.0)
164
+ irb
165
+ rackup (>= 1.0.0)
136
166
  rake (>= 12.2)
137
- thor (~> 1.0)
138
- zeitwerk (~> 2.5)
167
+ thor (~> 1.0, >= 1.2.2)
168
+ zeitwerk (~> 2.6)
139
169
  rake (13.0.6)
170
+ rdoc (6.5.0)
171
+ psych (>= 4.0.0)
172
+ reline (0.3.9)
173
+ io-console (~> 0.5)
174
+ ruby2_keywords (0.0.5)
175
+ stringio (3.0.8)
140
176
  thor (1.2.2)
141
- timeout (0.3.2)
177
+ timeout (0.4.0)
142
178
  tzinfo (2.0.6)
143
179
  concurrent-ruby (~> 1.0)
144
- websocket-driver (0.7.5)
180
+ webrick (1.8.1)
181
+ websocket-driver (0.7.6)
145
182
  websocket-extensions (>= 0.1.0)
146
183
  websocket-extensions (0.1.5)
147
- zeitwerk (2.6.8)
184
+ zeitwerk (2.6.12)
148
185
 
149
186
  PLATFORMS
150
187
  arm64-darwin
151
- ruby
152
188
  x86_64-darwin
153
189
  x86_64-linux
154
190
 
@@ -156,4 +192,4 @@ DEPENDENCIES
156
192
  log_sanity!
157
193
 
158
194
  BUNDLED WITH
159
- 2.3.26
195
+ 2.4.10
data/README.md CHANGED
@@ -27,11 +27,16 @@ Example output: (Multi-line and extra whitespace added for readability; normally
27
27
 
28
28
  ### Installation
29
29
 
30
- Install the usual way:
30
+ For Rails 7.1+, use log_sanity 2.x:
31
31
  ```ruby
32
32
  gem 'log_sanity'
33
33
  ```
34
34
 
35
+ For Rails 5.2, 6.x, or 7.0, use log_sanity 1.x:
36
+ ```ruby
37
+ gem 'log_sanity', '~> 1'
38
+ ```
39
+
35
40
  By default, LogSanity does not enable itself. To do so, in `config/environments/production.rb` add:
36
41
  ```ruby
37
42
  config.logsanity.enabled = true
@@ -47,7 +52,7 @@ LogSanity initializes after running `application.rb` and `config/environments/*.
47
52
 
48
53
  However, `initializers/*.rb` may be used to reduce the scope of what's logged. For example, to skip logging of ActiveJob requests only:
49
54
  ```ruby
50
- # initializers/logsanity.rb
55
+ # initializers/log_sanity.rb
51
56
  LogSanity::LogSubscriber::ActiveJob.detach_from :active_job
52
57
  ```
53
58
 
@@ -130,7 +135,7 @@ However, if `true`, you'll see:
130
135
 
131
136
  ##### String formatting
132
137
 
133
- When LogSanity initializes, it replaces the Rails log formatter with its own, but saves the old one for outputting strings (assuming `json_strings` is `false`). This means you can still configure the formatting of those. For example, to use Logger's default formatting (instead of Rails' default):
138
+ When LogSanity initializes, it replaces the Rails log formatter with its own, but saves the old one for outputting strings (used when `json_strings` is `false`). This means you can still configure the formatting of those. For example, to use Logger's default formatting (instead of Rails' default):
134
139
 
135
140
  ```ruby
136
141
  config.log_formatter = ::Logger::Formatter.new
@@ -152,7 +157,7 @@ LogSanity takes these and adds them to the default request log entry (but _not_
152
157
 
153
158
  ### Additional notes
154
159
 
155
- 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).
160
+ 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 queries).
156
161
 
157
162
  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):
158
163
  ```ruby
@@ -161,8 +166,6 @@ config.logger = ActiveSupport::Logger.new(STDOUT)
161
166
 
162
167
  All default output includes the :uuid/:request_id using the key "rq". There is no need to add \[:uuid] to `config.log_tags`.
163
168
 
164
- `ActionController::RoutingError` exceptions are always silenced and turned into a simple 404 log entry.
165
-
166
169
  The request path is not included, as it mostly just duplicates `route` and `params`. If you need it, you could add it using `config.log_tags = [:filtered_path]`. Alternatively, consider adding X-Request-Id to your `nginx` (or other webserver) logs and correlating to those logs instead.
167
170
 
168
171
  The `total` duration may be longer than you're used to seeing. By default, Rails only counts the time inside the application controller. In contrast, LogSanity also includes all the middleware between itself and the application controller. While this isn't the entire picture, it is closer to the actual real time elapsed.
@@ -173,7 +176,6 @@ The `total` duration may be longer than you're used to seeing. By default, Rails
173
176
  In short:
174
177
  * Removes all default Rails logging, replacing it with its own
175
178
  * Replaces Rails::Rack::Logger middleware with its own
176
- * Adds middleware to intercept routing errors
177
179
  * Replaces the current logger's formatter
178
180
 
179
181
 
@@ -0,0 +1,13 @@
1
+ module LogSanity
2
+ module Extensions
3
+ module BroadcastLogger
4
+ extend ActiveSupport::Concern
5
+
6
+ def initialize_copy(other)
7
+ super
8
+ @broadcasts = other.broadcasts.deep_dup
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -35,6 +35,10 @@ module LogSanity
35
35
  end
36
36
  end
37
37
 
38
+ def redirect(event)
39
+ log 'redirect', event.payload[:location]
40
+ end
41
+
38
42
 
39
43
  private
40
44
 
@@ -13,6 +13,11 @@ module LogSanity
13
13
  'queue' => job.queue_name
14
14
  }
15
15
  e['params'] = job.arguments if job.arguments.any?
16
+ if error = event.payload[:exception_object] || job.enqueue_error
17
+ e['error'] = error
18
+ elsif event.payload[:aborted]
19
+ e['callback_halt'] = 'before_enqueue'
20
+ end
16
21
  e
17
22
  end
18
23
  end
@@ -29,10 +34,27 @@ module LogSanity
29
34
  'start_at' => job.scheduled_at
30
35
  }
31
36
  e['params'] = job.arguments if job.arguments.any?
37
+ if error = event.payload[:exception_object] || job.enqueue_error
38
+ e['error'] = error
39
+ elsif event.payload[:aborted]
40
+ e['callback_halt'] = 'before_enqueue'
41
+ end
32
42
  e
33
43
  end
34
44
  end
35
45
 
46
+ def enqueue_all(event)
47
+ info do
48
+ total = event.payload[:jobs].size
49
+ enqueued = event.payload[:enqueued_count]
50
+ { 'at' => Time.now,
51
+ 'event' => 'bulk_enqueue',
52
+ 'enqueued' => enqueued,
53
+ 'failed' => total - enqueued,
54
+ }
55
+ end
56
+ end
57
+
36
58
  # def perform_start(event)
37
59
  # info do
38
60
  # job = event.payload[:job]
@@ -60,6 +82,11 @@ module LogSanity
60
82
  'duration' => {'total' => event.duration.round}
61
83
  }
62
84
  e['params'] = job.arguments if job.arguments.any?
85
+ if error = event.payload[:exception_object]
86
+ e['error'] = error
87
+ elsif event.payload[:aborted]
88
+ e['callback_halt'] = 'before_perform'
89
+ end
63
90
  e
64
91
  end
65
92
  end
@@ -9,15 +9,21 @@ module LogSanity
9
9
  request = ActionDispatch::Request.new(env)
10
10
 
11
11
  conditionally_silence(request) do |silence|
12
+ payload = {env: env, request: request, silence: silence}
13
+ handle = start(payload)
12
14
  begin
13
- start(request: request)
14
- resp = @app.call(env)
15
- resp[2] = Rack::BodyProxy.new(resp[2]) do
16
- finish(env: env, request: request, response: resp, silence: silence)
15
+ status, headers, body = response = @app.call(env)
16
+ payload[:response] = response
17
+ body = Rack::BodyProxy.new(body){ handle.finish }
18
+ if response.frozen?
19
+ [status, headers, body]
20
+ else
21
+ response[2] = body
22
+ response
17
23
  end
18
- resp
19
24
  rescue Exception => e
20
- finish(env: env, request: request, exception: e, silence: silence)
25
+ payload[:exception] = e
26
+ handle.finish
21
27
  raise e
22
28
  end
23
29
  end
@@ -39,15 +45,12 @@ module LogSanity
39
45
 
40
46
  private
41
47
 
42
- def start(params)
48
+ def start(payload)
43
49
  LogSanity.reset_fields
44
50
  instrumenter = ActiveSupport::Notifications.instrumenter
45
- instrumenter.start 'request.action_dispatch', params
46
- end
47
-
48
- def finish(params)
49
- instrumenter = ActiveSupport::Notifications.instrumenter
50
- instrumenter.finish 'request.action_dispatch', params
51
+ instrumenter.build_handle('request.action_dispatch', payload).tap do |handle|
52
+ handle.start
53
+ end
51
54
  end
52
55
 
53
56
  def silence_path?(request)
@@ -13,73 +13,72 @@ module LogSanity
13
13
  end
14
14
 
15
15
  initializer "log_sanity.configure", before: :load_config_initializers do |app|
16
+ ActiveSupport::BroadcastLogger.include LogSanity::Extensions::BroadcastLogger
16
17
  app.config.log_tags ||= []
18
+
17
19
  if app.config.logsanity.enabled
18
20
  orig_formatter = Rails.logger.formatter
19
21
  Rails.logger.formatter = LogSanity::Formatter.new
20
22
  if app.config.logsanity.json_strings
21
23
  Rails.logger.formatter.string_formatter = false
22
- else
23
- Rails.logger.formatter.string_formatter = orig_formatter if orig_formatter
24
+ elsif orig_formatter
25
+ Rails.logger.formatter.string_formatter = orig_formatter
26
+ end
27
+
28
+ app.middleware.swap Rails::Rack::Logger, LogSanity::RequestLogger
29
+
30
+ ActiveSupport.on_load(:action_cable_connection) do
31
+ prepend LogSanity::Extensions::ActionCableConnection
32
+ end
33
+
34
+ ActiveSupport.on_load(:action_cable) do
35
+ # set just ActionCable's logger to :warn to silence several non-instrumented logs
36
+ orig_logger = logger || Rails.logger
37
+ if orig_logger.level < Logger::WARN
38
+ self.logger = orig_logger.clone.tap do |l|
39
+ l.level = Logger::WARN
40
+ end
41
+ end
42
+ LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
24
43
  end
25
44
 
26
- if defined?(ActionController)
27
- require 'action_controller/log_subscriber'
45
+ ActiveSupport.on_load(:action_controller, run_once: true) do
28
46
  ActionController::LogSubscriber.detach_from :action_controller
47
+ LogSanity::LogSubscriber::ActionController.attach_to :action_controller
29
48
  end
30
- if defined?(ActionMailer)
31
- require 'action_mailer/log_subscriber'
49
+
50
+ ActiveSupport.on_load(:action_dispatch_request) do
51
+ ActionDispatch::LogSubscriber.detach_from :action_dispatch
52
+ LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
53
+ end
54
+
55
+ ActiveSupport.on_load(:action_mailer) do
32
56
  ActionMailer::LogSubscriber.detach_from :action_mailer
57
+ LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
33
58
  end
34
- if defined?(ActionView)
35
- require 'action_view/log_subscriber'
59
+
60
+ ActiveSupport.on_load(:action_view) do
36
61
  ActionView::LogSubscriber.detach_from :action_view
37
- end
38
- if defined?(ActiveJob)
39
- require 'active_job/logging'
40
- begin
41
- require 'active_job/log_subscriber' # >= 6.1
42
- rescue LoadError
43
- end
44
- if defined?(ActiveJob::LogSubscriber) # >= 6.1
45
- ActiveJob::LogSubscriber.detach_from :active_job
46
- else # < 6.1
47
- ActiveJob::Logging::LogSubscriber.detach_from :active_job
62
+ if ActionView::LogSubscriber.logger.debug?
63
+ ActiveSupport::Notifications.unsubscribe 'render_template.action_view'
64
+ ActiveSupport::Notifications.unsubscribe 'render_layout.action_view'
48
65
  end
49
66
  end
50
- if defined?(ActiveRecord)
51
- # require 'active_record/log_subscriber'
67
+
68
+ ActiveSupport.on_load(:active_job) do
69
+ ActiveJob::LogSubscriber.detach_from :active_job
70
+ LogSanity::LogSubscriber::ActiveJob.attach_to :active_job
71
+ end
72
+
73
+ ActiveSupport.on_load(:active_record) do
52
74
  # ActiveRecord::LogSubscriber.detach_from :active_record
53
- # this turns off measurements too
75
+ # only logs at :debug level. since log_sanity offers no replacements, don't detach. if logging in
76
+ # production at :debug, may silence anyway by adding an initializer with the above detach_from.
54
77
  if ActiveRecord::Base.logger.debug?
55
78
  Rails.logger.info '[LogSanity] ActiveRecord::Base.logger in debug mode and will still log queries'
56
79
  end
57
80
  end
58
81
 
59
- ActiveSupport.on_load(:action_cable) do
60
- if Rails.version < '7.1'
61
- orig_logger = logger || Rails.logger
62
- if orig_logger.level < Logger::WARN
63
- self.logger = orig_logger.clone.tap do |l|
64
- l.level = Logger::WARN
65
- end
66
- end
67
- end
68
- end
69
- ActiveSupport.on_load(:action_cable_connection) do
70
- prepend LogSanity::Extensions::ActionCableConnection
71
- end
72
-
73
- LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
74
- LogSanity::LogSubscriber::ActionController.attach_to :action_controller
75
- LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
76
- LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
77
- LogSanity::LogSubscriber::ActiveJob.attach_to :active_job
78
-
79
- app.middleware.swap Rails::Rack::Logger, LogSanity::RequestLogger
80
-
81
- show_exceptions_app = app.config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
82
- app.middleware.use LogSanity::RoutingErrorCatcher, show_exceptions_app
83
82
  end
84
83
  end
85
84
 
@@ -1,3 +1,3 @@
1
1
  module LogSanity
2
- VERSION = '1.3.2'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/log_sanity.rb CHANGED
@@ -1,28 +1,25 @@
1
- %w( formatter
2
- railtie
3
- log_subscribers/base
4
- log_subscribers/action_cable
5
- log_subscribers/action_controller
6
- log_subscribers/action_dispatch
7
- log_subscribers/action_mailer
8
- log_subscribers/active_job
9
- middleware/request_logger
10
- middleware/routing_error_catcher
11
- extensions/action_cable_connection
12
- extensions/action_controller_helper
13
- extensions/active_support_subscriber
14
- ).each do |fn|
1
+ %w(
2
+ formatter
3
+ railtie
4
+ log_subscribers/base
5
+ log_subscribers/action_cable
6
+ log_subscribers/action_controller
7
+ log_subscribers/action_dispatch
8
+ log_subscribers/action_mailer
9
+ log_subscribers/active_job
10
+ middleware/request_logger
11
+ extensions/action_cable_connection
12
+ extensions/action_controller_helper
13
+ extensions/broadcast_logger
14
+ ).each do |fn|
15
15
  require_relative "log_sanity/#{fn}"
16
16
  end
17
17
 
18
- if Rails.version < '6'
19
- ActiveSupport::Subscriber.include LogSanity::Extensions::ActiveSupportSubscriber
20
- end
21
-
22
18
  module LogSanity
23
19
  module_function
24
20
 
25
21
  def fields
22
+ # this is fiber-local
26
23
  Thread.current[:logsanity_fields] || reset_fields
27
24
  end
28
25
 
data/log_sanity.gemspec CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency 'rails', '>= 5.2', '< 7.2'
20
+ s.add_dependency 'rails', '>= 7.1', '< 7.2'
21
21
  end
@@ -12,6 +12,8 @@ require "log_sanity"
12
12
 
13
13
  module Dummy
14
14
  class Application < Rails::Application
15
+ config.load_defaults Rails::VERSION::STRING.to_f
16
+
15
17
  # Settings in config/environments/* take precedence over those specified here.
16
18
  # Application configuration should go into files in config/initializers
17
19
  # -- all .rb files in that directory are automatically loaded.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_sanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '7.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '7.2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.2'
29
+ version: '7.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7.2'
@@ -48,7 +48,7 @@ files:
48
48
  - lib/log_sanity.rb
49
49
  - lib/log_sanity/extensions/action_cable_connection.rb
50
50
  - lib/log_sanity/extensions/action_controller_helper.rb
51
- - lib/log_sanity/extensions/active_support_subscriber.rb
51
+ - lib/log_sanity/extensions/broadcast_logger.rb
52
52
  - lib/log_sanity/formatter.rb
53
53
  - lib/log_sanity/log_subscribers/action_cable.rb
54
54
  - lib/log_sanity/log_subscribers/action_controller.rb
@@ -57,7 +57,6 @@ files:
57
57
  - lib/log_sanity/log_subscribers/active_job.rb
58
58
  - lib/log_sanity/log_subscribers/base.rb
59
59
  - lib/log_sanity/middleware/request_logger.rb
60
- - lib/log_sanity/middleware/routing_error_catcher.rb
61
60
  - lib/log_sanity/railtie.rb
62
61
  - lib/log_sanity/version.rb
63
62
  - lib/tasks/log_sanity_tasks.rake
@@ -1,25 +0,0 @@
1
- module LogSanity
2
- module Extensions
3
- module ActiveSupportSubscriber
4
- extend ActiveSupport::Concern
5
-
6
- module ClassMethods
7
- def detach_from(namespace, notifier=ActiveSupport::Notifications)
8
- subscribers.select{|s| s.is_a? self}.each do |subscriber|
9
- subscriber.public_methods(false).each do |event|
10
- pattern = "#{event}.#{namespace}"
11
- notifier.notifier.listeners_for(pattern).each do |listener|
12
- if listener.instance_variable_get(:@delegate) == subscriber
13
- notifier.unsubscribe listener
14
- subscriber.patterns.delete pattern
15
- end
16
- end
17
- end
18
- subscribers.delete subscriber if subscriber.patterns.empty?
19
- end
20
- end
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,40 +0,0 @@
1
- # middleware to catch and sanely handle routing errors without treating them
2
- # like all other exceptions (that is, without verbose backtraces and other
3
- # such).
4
- # intended to be added to the end of the middleware stack (nearest the app).
5
- # while built on top of ShowExceptions to reuse its error rendering logic,
6
- # does not replace it.
7
-
8
- module LogSanity
9
- class RoutingErrorCatcher < ActionDispatch::ShowExceptions
10
-
11
- def call(env)
12
- request = ActionDispatch::Request.new env
13
- _, headers, body = response = @app.call(env)
14
-
15
- if headers['X-Cascade'] == 'pass'
16
- body.close if body.respond_to?(:close)
17
- raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
18
- end
19
-
20
- response
21
- rescue ActionController::RoutingError => exception
22
- if Rails.version >= '7.1'
23
- backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner')
24
- wrapper = ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, exception)
25
- if wrapper.show?(request)
26
- render_exception(request, wrapper)
27
- else
28
- raise exception
29
- end
30
- else
31
- if request.show_exceptions?
32
- render_exception(request, exception)
33
- else
34
- raise exception
35
- end
36
- end
37
- end
38
-
39
- end
40
- end