From fede58289bd3e4ff7573b36d3d1b1b6a340ad81e Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Mon, 11 Mar 2019 17:26:19 +0100 Subject: [PATCH] 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. --- config/environments/development.rb | 5 ++--- config/environments/staging.rb | 3 --- config/initializers/cache_store.rb | 7 +++++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 config/initializers/cache_store.rb diff --git a/config/environments/development.rb b/config/environments/development.rb index 3ec137a12a..20310726cb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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 diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 0595e49495..b0e1b96301 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -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" diff --git a/config/initializers/cache_store.rb b/config/initializers/cache_store.rb new file mode 100644 index 0000000000..009ebbaab6 --- /dev/null +++ b/config/initializers/cache_store.rb @@ -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