ankane / logstop

Keep personal data out of your logs
MIT License
240 stars 13 forks source link

Scrub Active Record attributes by names #9

Closed piotrwodz closed 3 years ago

piotrwodz commented 3 years ago

Enhancement

Closes: https://github.com/ankane/logstop/issues/8

Description

When using logstop in Rails and willing to scrub some Active Record attributes from query logs, run this generator:

rails generate config:logstop

override scrub_attributes and enable active_record option in guard method e.g.:

Logstop.configure do |config|
  config.scrub_attributes = %w[week_date]
end

Logstop.guard(Rails.logger, active_record: true)

Output:

Screenshot 2021-01-03 at 14 48 49

Why should this be added

Add an option of filtering Active Record query logs by passing attribute names.

Checklist

piotrwodz commented 3 years ago

@ankane Hi Andrew 👋 I am curious about your feedback. This code has been run in two different projects and seems to be working fine :) Sharing with you now.

FYI: I have not yet written any tests.

ankane commented 3 years ago

Hey @piotrwodz, thanks for the PR! I think this feature would be better for Active Record than Logstop (wouldn't need to rely on regular expressions). However, it may be better to disable SQL logging if this is needed, since it won't be able to filter things like:

Lesson.where("week_date = ?", week_date) 
piotrwodz commented 3 years ago

Thanks! You found a good example and of course it would need to be filtered as well.

Regarding SQL logging being disabled: of course you can do it. However, Rails has debug mode by design (also in production) and I think, depending on the app you are developing, it makes sense to keep on logging SQL queries. You might still want to inspect these queries but with attributes being filtered.

I think this feature would be better for Active Record than Logstop (wouldn't need to rely on regular expressions).

👍