Move Cache::Store config to new initializer

I don't know why but `Rails.logger` is still nil when evaluated from
`configure` block in `config/environments/development.rb`. The only way
I found to make ActiveSupport's cache to use the default logger is from
an initializer.

Note that `ActiveSupport::Cache::Store` uses `debug` level and so we
need to set the dev logger in that same level to see its messages. If
you want to debug in staging as well, you'll need to modify the log
level manually.
This commit is contained in:
Pau Perez
2019-03-11 17:26:19 +01:00
parent 15a95a3bf5
commit fede58289b
3 changed files with 9 additions and 6 deletions

View File

@@ -9,9 +9,6 @@ Openfoodnetwork::Application.configure do
# :file_store is used by default when no cache store is specifically configured.
# config.cache_store = :file_store
# Enable cache instrumentation, which is disabled by default
ActiveSupport::Cache::Store.instrument = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
@@ -45,4 +42,6 @@ Openfoodnetwork::Application.configure do
# Show emails using Letter Opener
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { host: "0.0.0.0:3000" }
config.log_level = :debug
end

View File

@@ -42,9 +42,6 @@ Openfoodnetwork::Application.configure do
# Use a different cache store in production
config.cache_store = :dalli_store
# Enable cache instrumentation, which is disabled by default
ActiveSupport::Cache::Store.instrument = true
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

View File

@@ -0,0 +1,7 @@
unless Rails.env.production?
# Enable cache instrumentation, which is disabled by default
ActiveSupport::Cache::Store.instrument = true
# Log message in the same default logger
ActiveSupport::Cache::Store.logger = Rails.logger
end