Skip to content
Permalink
Browse files

Merge pull request #28266 from Stellenticket/allow_disable_server_std…

…out_logging

rails server: Allow to explicitly specify whether to output Rails's log to stdout
  • Loading branch information...
kaspth committed Jul 8, 2018
2 parents 875a06b + 889a7cc commit 50a9ca665d51cd3298af8b3c1dabf20ad5ce77da
Showing with 21 additions and 2 deletions.
  1. +9 −2 railties/lib/rails/commands/server/server_command.rb
  2. +12 −0 railties/test/commands/server_test.rb
@@ -132,13 +132,14 @@ class ServerCommand < Base # :nodoc:
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 @@ def server_options
{
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 @@ def early_hints
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
@@ -143,10 +143,22 @@ def test_log_stdout
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)

0 comments on commit 50a9ca6

Please sign in to comment.
You can’t perform that action at this time.