RailsのLogでのパラメータをFILTEREDする。


Railsでpasswordパラメータはデフォルトで見えなくなってますね。

Started POST "/users" for ::1 at 2015-06-29 14:16:14 +0900
Processing by UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZrB1VEJ6B0nd7GxJ/BkxybIpF2jAyqhT6DjCx6YOuOXyK6kRBn75IPeN1RO/DHhEvJ1VyA96H6XHg8Cfsb6Jww==", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"submit"}

ここにemailもLogに見せたくない場合。

config/initializers/filter_parameter_logging.rb
Rails.application.config.filter_parameters += [:password]

# emailも付与する
Rails.application.config.filter_parameters += [:password, :email]

こうすると、↓になる。

Started POST "/users" for ::1 at 2015-06-29 14:18:34 +0900
Processing by UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZrB1VEJ6B0nd7GxJ/BkxybIpF2jAyqhT6DjCx6YOuOXyK6kRBn75IPeN1RO/DHhEvJ1VyA96H6XHg8Cfsb6Jww==", "user"=>{"email"=>"[FILTERED]", "password"=>"[FILTERED]"}, "commit"=>"submit"}