Fix #401: use a Railtie to set Hashie.logger on rails boot.
This commit is contained in:
parent
74b3bd6ab6
commit
c269a1cc98
|
@ -28,6 +28,7 @@ scheme are considered to be bugs.
|
|||
|
||||
### Fixed
|
||||
|
||||
* [#402](https://github.com/intridea/hashie/pull/402): Use a Railtie to set Hashie.logger on rails boot - [@matthewrudy](https://github.com/matthewrudy).
|
||||
* Your contribution here.
|
||||
|
||||
### Security
|
||||
|
|
|
@ -56,4 +56,6 @@ module Hashie
|
|||
include Hashie::Extensions::StringifyKeys::ClassMethods
|
||||
include Hashie::Extensions::SymbolizeKeys::ClassMethods
|
||||
end
|
||||
|
||||
require 'hashie/railtie' if defined?(::Rails)
|
||||
end
|
||||
|
|
|
@ -5,12 +5,7 @@ module Hashie
|
|||
#
|
||||
# @return [Logger]
|
||||
def self.logger
|
||||
@logger ||=
|
||||
if defined?(::Rails)
|
||||
Rails.logger
|
||||
else
|
||||
Logger.new(STDOUT)
|
||||
end
|
||||
@logger ||= Logger.new(STDOUT)
|
||||
end
|
||||
|
||||
# Sets the logger that Hashie uses for reporting errors.
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
require 'rails/railtie'
|
||||
|
||||
module Hashie
|
||||
class Railtie < Rails::Railtie
|
||||
# Set the Hashie.logger to use Rails.logger when used with rails.
|
||||
initializer 'hashie.configure_logger', after: 'initialize_logger' do
|
||||
Hashie.logger = Rails.logger
|
||||
end
|
||||
end
|
||||
end
|
|
@ -62,9 +62,10 @@ Rails.application.config.middleware.use OmniAuth::Builder do
|
|||
provider :some_site
|
||||
end
|
||||
|
||||
RailsApp::Application.initialize!
|
||||
|
||||
# the order is important
|
||||
# hashie must be loaded first to register the railtie
|
||||
require 'hashie'
|
||||
RailsApp::Application.initialize!
|
||||
|
||||
RSpec.describe 'the Hashie logger' do
|
||||
it 'is set to the Rails logger' do
|
||||
|
|
|
@ -55,9 +55,11 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
RailsApp::Application.initialize!
|
||||
|
||||
# the order is important
|
||||
# hashie must be loaded first to register the railtie
|
||||
# then we can initialize
|
||||
require 'hashie'
|
||||
RailsApp::Application.initialize!
|
||||
|
||||
RSpec.describe 'the Hashie logger' do
|
||||
it 'is set to the Rails logger' do
|
||||
|
|
Loading…
Reference in New Issue