mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Restore sync=true on global stdout/stderr streams (#2557)
* Restore sync=true on STDOUT/STDERR streams * Move mutation of STDOUT and STDERR streams to `redirect_io` This isn't technically related to redirecting the STDOUT and STDERR streams, but moving it here keeps all of the STDOUT/STDERR logic together. It seems like a more natural place to put it. * Add a test to ensure that STDOUT is flushed by default
This commit is contained in:
parent
1555ca248e
commit
7a2cdf6a7e
6 changed files with 25 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
* Add `#flush` and `#sync` methods to `Puma::NullIO` ([#2553])
|
* Add `#flush` and `#sync` methods to `Puma::NullIO` ([#2553])
|
||||||
|
* Restore `sync=true` on `STDOUT` and `STDERR` streams #2557
|
||||||
|
|
||||||
## 5.2.1 / 2021-02-05
|
## 5.2.1 / 2021-02-05
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,8 @@ module Puma
|
||||||
:first_data_timeout => Const::FIRST_DATA_TIMEOUT,
|
:first_data_timeout => Const::FIRST_DATA_TIMEOUT,
|
||||||
:raise_exception_on_sigterm => true,
|
:raise_exception_on_sigterm => true,
|
||||||
:max_fast_inline => Const::MAX_FAST_INLINE,
|
:max_fast_inline => Const::MAX_FAST_INLINE,
|
||||||
:io_selector_backend => :auto
|
:io_selector_backend => :auto,
|
||||||
|
:mutate_stdout_and_stderr_to_sync_on_write => true,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -888,5 +888,9 @@ module Puma
|
||||||
def io_selector_backend(backend)
|
def io_selector_backend(backend)
|
||||||
@options[:io_selector_backend] = backend.to_sym
|
@options[:io_selector_backend] = backend.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mutate_stdout_and_stderr_to_sync_on_write(enabled=true)
|
||||||
|
@options[:mutate_stdout_and_stderr_to_sync_on_write] = enabled
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -126,6 +126,11 @@ module Puma
|
||||||
STDERR.puts "=== puma startup: #{Time.now} ==="
|
STDERR.puts "=== puma startup: #{Time.now} ==="
|
||||||
STDERR.flush unless STDERR.sync
|
STDERR.flush unless STDERR.sync
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @options[:mutate_stdout_and_stderr_to_sync_on_write]
|
||||||
|
STDOUT.sync = true
|
||||||
|
STDERR.sync = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_and_bind
|
def load_and_bind
|
||||||
|
|
6
test/rackup/write_to_stdout.ru
Normal file
6
test/rackup/write_to_stdout.ru
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
app = lambda do |env|
|
||||||
|
$stdout.write "hello\n"
|
||||||
|
[200, {"Content-Type" => "text/plain"}, ["Hello World"]]
|
||||||
|
end
|
||||||
|
|
||||||
|
run app
|
|
@ -163,4 +163,11 @@ class TestIntegrationSingle < TestIntegration
|
||||||
assert(!File.file?("t2-pid"))
|
assert(!File.file?("t2-pid"))
|
||||||
assert_equal("Puma is started\n", out)
|
assert_equal("Puma is started\n", out)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_application_logs_are_flushed_on_write
|
||||||
|
cli_server 'test/rackup/write_to_stdout.ru'
|
||||||
|
read_body connect
|
||||||
|
log_line = @server.gets
|
||||||
|
assert_equal "hello\n", log_line
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue