I allow users to upload files on my site. And some of those files can be very large and it eats up a huge chunk of my log files. So I would like to not have it show up. I know about:
config.filter_parameters += [:password]
To filter certain parameters. But the problem with this is that it the parameter is in a hash like this:
{
:person => {
:name => 'bob',
:file => {
:data => 'really long data. this can be tens of thousands of characters long'
}
}
}
I could add :data to the filter_parameters but that would hiding lots of logs across the whole site since data is a common key (I also can't rename this to something more obscure). Is it possible for filter_parameters to take in a nested parameter? Or is there another way to limit the length of all parameters so if they come in bigger than a certain size, it would not be stored in my log files.
I ended up putting something like this in my application.rb
config.filter_parameters << lambda do |k, v|
if k == 'data' && v && v.class == String && v.length > 1024
v.replace('[FILTER]')
end
end
I couldn't find a better way to do this. So I look for the key 'data' in the params. And if the value for that data is a String and over a certain length, I just replace it so the logs isn't so cluttered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With