Skip to content

Default the logger to the Rails logger #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-20
x86_64-darwin-22
x86_64-linux
Expand Down
2 changes: 2 additions & 0 deletions lib/solid_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
module SolidCache
mattr_accessor :executor
mattr_accessor :configuration, default: Configuration.new

ActiveSupport.run_load_hooks(:solid_cache, self)
end

loader.eager_load
12 changes: 10 additions & 2 deletions lib/solid_cache/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ class Engine < ::Rails::Engine
SolidCache.executor = config.solid_cache.executor || app.executor
end

config.after_initialize do
Rails.cache.setup! if Rails.cache.is_a?(Store)
initializer "solid_cache.logger" do
ActiveSupport.on_load(:solid_cache) do
Store.logger ||= Rails.logger
end
end

initializer "solid_cache.setup" do
ActiveSupport.on_load(:solid_cache) do
Rails.cache.setup! if Rails.cache.is_a?(Store)
end
end

config.after_initialize do
Expand Down
4 changes: 4 additions & 0 deletions test/unit/solid_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def test_write_expired_value_with_unless_exist
travel 2.seconds
assert_equal true, @cache.write(1, "bbbb", expires_in: 1.second, unless_exist: true)
end

test "store logger defaults to Rails logger" do
assert_equal Rails.logger, @cache.logger
end
end

class SolidCacheFailsafeTest < ActiveSupport::TestCase
Expand Down
Loading