Skip to content

Commit 665b4e0

Browse files
committed
Default the logger to the Rails logger
Ensure errors are logged to the Rails logger by default. Also re-use the new load hook to call setup! on the cache store.
1 parent ba32918 commit 665b4e0

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ PLATFORMS
183183
arm64-darwin-21
184184
arm64-darwin-22
185185
arm64-darwin-23
186+
arm64-darwin-24
186187
x86_64-darwin-20
187188
x86_64-darwin-22
188189
x86_64-linux

lib/solid_cache.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
module SolidCache
1212
mattr_accessor :executor
1313
mattr_accessor :configuration, default: Configuration.new
14+
15+
ActiveSupport.run_load_hooks(:solid_cache, self)
1416
end
1517

1618
loader.eager_load

lib/solid_cache/engine.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ class Engine < ::Rails::Engine
3636
SolidCache.executor = config.solid_cache.executor || app.executor
3737
end
3838

39-
config.after_initialize do
40-
Rails.cache.setup! if Rails.cache.is_a?(Store)
39+
initializer "solid_cache.logger" do
40+
ActiveSupport.on_load(:solid_cache) do
41+
Store.logger ||= Rails.logger
42+
end
43+
end
44+
45+
initializer "solid_cache.setup" do
46+
ActiveSupport.on_load(:solid_cache) do
47+
Rails.cache.setup! if Rails.cache.is_a?(Store)
48+
end
4149
end
4250

4351
config.after_initialize do

test/unit/solid_cache_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def test_write_expired_value_with_unless_exist
6565
travel 2.seconds
6666
assert_equal true, @cache.write(1, "bbbb", expires_in: 1.second, unless_exist: true)
6767
end
68+
69+
test "store logger defaults to Rails logger" do
70+
assert_equal Rails.logger, @cache.logger
71+
end
6872
end
6973

7074
class SolidCacheFailsafeTest < ActiveSupport::TestCase

0 commit comments

Comments
 (0)