aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
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 /railties/lib
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 'railties/lib')
-rw-r--r--railties/lib/rails/commands/server.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index d3ea441f8e..45d649ec31 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -133,11 +133,13 @@ module Rails
def log_to_stdout
wrapped_app # touch the app so the logger is set up
- console = ActiveSupport::Logger.new($stdout)
+ console = ActiveSupport::Logger.new(STDOUT)
console.formatter = Rails.logger.formatter
console.level = Rails.logger.level
- Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
+ unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
+ Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
+ end
end
end
end