aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-01-05 16:23:43 -0600
committerschneems <richard.schneeman@gmail.com>2016-01-06 09:55:35 -0600
commit3d10d9d6c3b831fe9632c43a0ffec46104f912a7 (patch)
tree0f4e2050c58d477d93e048c71a1cc7c6f3f3f5d2 /activerecord
parent9dcb1b9b074e313fe0d2a738345c623620f594a2 (diff)
downloadrails-3d10d9d6c3b831fe9632c43a0ffec46104f912a7.tar.gz
rails-3d10d9d6c3b831fe9632c43a0ffec46104f912a7.tar.bz2
rails-3d10d9d6c3b831fe9632c43a0ffec46104f912a7.zip
[close #22917] Don't output to `STDOUT` twice
When `rails console` or `rails server` are used along with a logger set to output to `STDOUT` then the contents will show up twice. This happens because the logger is extended with `ActiveSupportLogger.broadcast` with a destination of STDOUT even if it is already outputting to `STDOUT`. Previously PR #22592 attempted to fix this issue, but it ended up causing NoMethodErrors. A better approach than relying on adding a method and flow control is to inspect the log destination directly. For this `ActiveSupport::Logger.logger_outputs_to?` was introduced ```ruby logger = Logger.new(STDOUT) ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT) # => true ``` To accomplish this we must look inside of an instance variable of standard lib's Logger `@logdev`. There is a related Ruby proposal to expose this method in a standard way: https://bugs.ruby-lang.org/issues/11955
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/railtie.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index f5e69ec4fb..17fbe5a742 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -57,8 +57,10 @@ module ActiveRecord
console do |app|
require "active_record/railties/console_sandbox" if app.sandbox?
require "active_record/base"
- console = ActiveSupport::Logger.new(STDERR)
- Rails.logger.extend ActiveSupport::Logger.broadcast console
+ unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDERR, STDOUT)
+ console = ActiveSupport::Logger.new(STDERR)
+ Rails.logger.extend ActiveSupport::Logger.broadcast console
+ end
end
runner do