Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter nested parameters from Rails logs

I see that I can filter keys from Rails logs here, but it's not entirely clear how I can filter a key that is nested inside the parameter hash.

My params hash looks like this:

{"download"=>{"attachment_id"=>"54039", "data"=>"data:image/png;base64,iVBORw0..."}}

Where params[:download][:data] is a base64 string. It is a large amount of data and I would like to remove it from my logs.

Is this possible?

I'm using Rails 4.0.4

like image 578
mehulkar Avatar asked Mar 21 '15 09:03

mehulkar


1 Answers

Simply put this in application.rb:

config.filter_parameters += [:data]

This would filter nested [:data] keys also.

In rails 5, you can define hierarchy of the key:

config.filter_parameters += ["download.data"]

This would filter all the [:data] keys which have [:download] as the immediate parent.

like image 175
Vijay Agrawal Avatar answered Sep 20 '22 05:09

Vijay Agrawal