timber-ruby
timber-ruby copied to clipboard
Timber silence log from action_on_unpermitted_parameters
It seems that timber is silencing the logs from action_on_unpermitted_parameters, I currently have set in developement.rb the following configuration:
config.action_controller.action_on_unpermitted_parameters = :log
I also tried to set the silence integration to false:
config.integrations.action_controller.silence = false
But it still doesn't log the unpermitted params, maybe I missed something in the configuration, any help ?
Hi @jonquach, that's odd. We'll take a look and see what's going on. Thanks for reporting.
Hi @jonquach, good news and bad news. The bad news is that we could not reproduce; we tested this extensively and confirmed that it is working for us. The good news is that I'm thinking your log level is not set to :debug which would be a very easy fix. Notice here that the method is part of the ActionController::LogSubscriber class and the message is logged at the debug level. Then, if you head over to the TimberLogSubscriber class you'll notice it extends the same ActionController::LogSubscriber class. That method is included through inheritance.
An easy way to test on your end is to do throw this temporary code in your config/initializers/timber.rb file:
# config/initializers/timber.rb
class ::ActionController::LogSubsucriber
def unpermitted_parameters(event)
info do
unpermitted_keys = event.payload[:keys]
"Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.map { |e| ":#{e}" }.join(", ")}"
end
end
end
This patch will raise the level to info and you will (hopefully) see these log messages again. Let me know if that helps.
Hello @binarylogic, thanks for your help
I checked and the log level is correctly set at :debug, and still nothing.
I tried to add the code you provided into config/initializers/timber.rb but it seems that it's not taken into account, I tried to put some print and the method isn't called at all.
But, after that I tried to edit the TimberLogSubscriber class to add the unpermitted_parameters method, and then it worked, correctly logged the Unpermitted parameter.
See gist here
Do you have any idea why ?
By the way, I notice that in the code snippet there is a typo on
class ::ActionController::LogSubsucriber
to
class ::ActionController::LogSubscriber
I tested on a new rails project from scratch, you can clone it here, it's the getting started from rails. I used rails 5.1.
In the article_controller.rb, only the params :title and :text are allowed, in the view articles/new.html.erb, there is a form with a extra params called :not_allowed_params that I passed for the creation, and it is not logged as an unpermitted params.

Hi @jonquach thank you for putting this together. Going to pull down your test app and see what's going on.