aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands/server/server_command.rb11
-rw-r--r--railties/test/commands/server_test.rb12
2 files changed, 21 insertions, 2 deletions
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index 194db23f14..070571f6f8 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -132,13 +132,14 @@ module Rails
desc: "Specifies whether to perform caching in development."
class_option :restart, type: :boolean, default: nil, hide: true
class_option :early_hints, type: :boolean, default: nil, desc: "Enables HTTP/2 early hints."
+ class_option :log_to_stdout, type: :boolean, default: nil, optional: true,
+ desc: "Whether to log to stdout. Enabled by default in development when not daemonized."
def initialize(args, local_options, *)
super
@original_options = local_options - %w( --restart )
deprecate_positional_rack_server_and_rewrite_to_option(@original_options)
- @log_stdout = options[:daemon].blank? && (options[:environment] || Rails.env) == "development"
end
def perform
@@ -166,7 +167,7 @@ module Rails
{
user_supplied_options: user_supplied_options,
server: using,
- log_stdout: @log_stdout,
+ log_stdout: log_to_stdout?,
Port: port,
Host: host,
DoNotReverseLookup: true,
@@ -256,6 +257,12 @@ module Rails
options[:early_hints]
end
+ def log_to_stdout?
+ options.fetch(:log_to_stdout) do
+ options[:daemon].blank? && environment == "development"
+ end
+ end
+
def pid
File.expand_path(options[:pid])
end
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index a20fece960..e5b1da6ea4 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -143,10 +143,22 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
options = parse_arguments(args)
assert_equal true, options[:log_stdout]
+ args = ["-e", "development", "-d"]
+ options = parse_arguments(args)
+ assert_equal false, options[:log_stdout]
+
args = ["-e", "production"]
options = parse_arguments(args)
assert_equal false, options[:log_stdout]
+ args = ["-e", "development", "--no-log-to-stdout"]
+ options = parse_arguments(args)
+ assert_equal false, options[:log_stdout]
+
+ args = ["-e", "production", "--log-to-stdout"]
+ options = parse_arguments(args)
+ assert_equal true, options[:log_stdout]
+
with_rack_env "development" do
args = []
options = parse_arguments(args)