Navigation Menu

Skip to content

Commit

Permalink
Fix #401: use a Railtie to set Hashie.logger on rails boot.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrudy authored and dblock committed Feb 10, 2017
1 parent 74b3bd6 commit c269a1c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/hashie.rb
Expand Up @@ -56,4 +56,6 @@ class << self
include Hashie::Extensions::StringifyKeys::ClassMethods
include Hashie::Extensions::SymbolizeKeys::ClassMethods
end

require 'hashie/railtie' if defined?(::Rails)
end
7 changes: 1 addition & 6 deletions lib/hashie/logger.rb
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions lib/hashie/railtie.rb
@@ -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
5 changes: 3 additions & 2 deletions spec/integration/omniauth-oauth2/integration_spec.rb
Expand Up @@ -62,9 +62,10 @@ def index
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
Expand Down
6 changes: 4 additions & 2 deletions spec/integration/rails/integration_spec.rb
Expand Up @@ -55,9 +55,11 @@ def index
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
Expand Down

0 comments on commit c269a1c

Please sign in to comment.