Skip to content

Commit 88dbbc8

Browse files
committed
Update README
1 parent 55dc144 commit 88dbbc8

File tree

1 file changed

+71
-68
lines changed

1 file changed

+71
-68
lines changed

README.md

+71-68
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,6 @@ The preferred type of notifications can be configured with:
127127
* `Prosopite.custom_logger = my_custom_logger`: Set a custom logger. See the following section for the details. Defaults to `false`.
128128
* `Prosopite.enabled = true`: Enables or disables the gem. Defaults to `true`.
129129

130-
### Custom Logging Configuration
131-
132-
You can supply a custom logger with the `Prosopite.custom_logger` setting.
133-
134-
This is useful for circumstances where you don't want your logs to be
135-
highlighted with red, or you want logs sent to a custom location.
136-
137-
One common scenario is that you may be generating json logs and sending them to
138-
Datadog, ELK stack, or similar, and don't want to have to remove the default red
139-
escaping data from messages sent to the Rails logger, or want to tag them
140-
differently with your own custom logger.
141-
142-
```ruby
143-
# Turns off logging with red highlights, but still sends them to the Rails logger
144-
Prosopite.custom_logger = Rails.logger
145-
```
146-
147-
```ruby
148-
# Use a completely custom logging instance
149-
Prosopite.custom_logger = MyLoggerClass.new
150-
151-
```
152-
153130
## Development Environment Usage
154131

155132
Prosopite auto-detection can be enabled on all controllers:
@@ -177,51 +154,6 @@ config.after_initialize do
177154
Prosopite.rails_logger = true
178155
end
179156
```
180-
In some cases you may want to configure prosopite to not raise by default and only raise in certain scenarios. In this example we scan on all controllers but also provide an API to only raise on specific actions.
181-
182-
```ruby
183-
Proposite.raise = false
184-
```
185-
186-
```ruby
187-
# app/controllers/application_controller.rb
188-
class ApplicationController < ActionController::Base
189-
def raise_on_n_plus_ones!(**options)
190-
return if Rails.env.production?
191-
192-
prepend_around_action(:_raise_on_n_plus_ones, **options)
193-
end
194-
195-
unless Rails.env.production?
196-
around_action :n_plus_one_detection
197-
198-
def n_plus_one_detection
199-
...
200-
end
201-
202-
def _raise_on_n_plus_ones
203-
Proposite.start_raise
204-
yield
205-
ensure
206-
Prosopite.stop_raise
207-
end
208-
end
209-
end
210-
```
211-
```ruby
212-
# app/controllers/books_controller.rb
213-
class BooksController < ApplicationController
214-
raise_on_n_plus_ones!(only: [:index])
215-
216-
def index
217-
@books = Book.all.map(&:author) # This will raise N+1 errors
218-
end
219-
220-
def show
221-
@book = Book.find(params[:id])
222-
@book.reviews.map(&:author) # This will not raise N+1 errors
223-
end
224-
end
225157
```
226158
## Test Environment Usage
227159
@@ -363,6 +295,77 @@ Pauses can be ignored with `Prosopite.ignore_pauses = true` in case you want to
363295
An example of when you might use this is if you are [testing Active Jobs inline](https://guides.rubyonrails.org/testing.html#testing-jobs),
364296
and don't want to run Prosopite on background job code, just foreground app code. In that case you could write an [Active Job callback](https://edgeguides.rubyonrails.org/active_job_basics.html#callbacks) that pauses the scan while the job is running.
365297

298+
## Local Raise
299+
300+
In some cases you may want to configure prosopite to not raise by default and only raise in certain scenarios.
301+
In this example we scan on all controllers but also provide an API to only raise on specific actions.
302+
303+
```ruby
304+
Proposite.raise = false
305+
```
306+
307+
```ruby
308+
# app/controllers/application_controller.rb
309+
class ApplicationController < ActionController::Base
310+
def raise_on_n_plus_ones!(**options)
311+
return if Rails.env.production?
312+
313+
prepend_around_action(:_raise_on_n_plus_ones, **options)
314+
end
315+
316+
unless Rails.env.production?
317+
around_action :n_plus_one_detection
318+
319+
def n_plus_one_detection
320+
...
321+
end
322+
323+
def _raise_on_n_plus_ones
324+
Proposite.start_raise
325+
yield
326+
ensure
327+
Prosopite.stop_raise
328+
end
329+
end
330+
end
331+
```
332+
```ruby
333+
# app/controllers/books_controller.rb
334+
class BooksController < ApplicationController
335+
raise_on_n_plus_ones!(only: [:index])
336+
337+
def index
338+
@books = Book.all.map(&:author) # This will raise N+1 errors
339+
end
340+
341+
def show
342+
@book = Book.find(params[:id])
343+
@book.reviews.map(&:author) # This will not raise N+1 errors
344+
end
345+
end
346+
347+
## Custom Logging Configuration
348+
349+
You can supply a custom logger with the `Prosopite.custom_logger` setting.
350+
351+
This is useful for circumstances where you don't want your logs to be
352+
highlighted with red, or you want logs sent to a custom location.
353+
354+
One common scenario is that you may be generating json logs and sending them to
355+
Datadog, ELK stack, or similar, and don't want to have to remove the default red
356+
escaping data from messages sent to the Rails logger, or want to tag them
357+
differently with your own custom logger.
358+
359+
```ruby
360+
# Turns off logging with red highlights, but still sends them to the Rails logger
361+
Prosopite.custom_logger = Rails.logger
362+
```
363+
364+
```ruby
365+
# Use a completely custom logging instance
366+
Prosopite.custom_logger = MyLoggerClass.new
367+
```
368+
366369
## Contributing
367370

368371
Bug reports and pull requests are welcome on GitHub at https://github.com/charkost/prosopite.

0 commit comments

Comments
 (0)