Skip to content
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

Let WebConsole.logger respect Rails.logger #244

Merged
merged 1 commit into from
Aug 23, 2017
Merged
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
5 changes: 3 additions & 2 deletions lib/web_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ module WebConsole
autoload :DoubleRenderError
end

mattr_accessor :logger
@@logger = ActiveSupport::Logger.new($stderr)
def self.logger
Rails.logger || (@logger ||= ActiveSupport::Logger.new($stderr))
end
end

require 'web_console/railtie'
4 changes: 0 additions & 4 deletions lib/web_console/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class Railtie < ::Rails::Railtie
initializer 'web_console.initialize' do
require 'bindex'
require 'web_console/extensions'

if logger = ::Rails.logger
WebConsole.logger = logger
end
end

initializer 'web_console.development_only' do
Expand Down
19 changes: 19 additions & 0 deletions test/web_console/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,25 @@ def body
assert_raises(RuntimeError) { get '/' }
end

test 'logs internal errors with Rails.logger' do
io = StringIO.new
logger = ActiveSupport::Logger.new(io)
old_logger, Rails.logger = Rails.logger, logger

begin
@app.stubs(:call_app).raises('whoops')

get '/'
rescue RuntimeError
output = io.rewind && io.read
lines = output.lines

assert_equal ["\n", "RuntimeError: whoops\n"], lines.slice!(0, 2)
ensure
Rails.logger = old_logger
end
end

private

# Override the put and post testing helper of ActionDispatch to customize http headers
Expand Down