From 37b78320daac5c79bca4e1def6510684cfc743b6 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Tue, 31 May 2022 19:28:43 -0500 Subject: [PATCH] log_writer.rb - add internal_write method (#2888) --- lib/puma/log_writer.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/puma/log_writer.rb b/lib/puma/log_writer.rb index 0277451b..842caa64 100644 --- a/lib/puma/log_writer.rb +++ b/lib/puma/log_writer.rb @@ -57,18 +57,22 @@ module Puma # Write +str+ to +@stdout+ def log(str) - @stdout.is_a?(IO) and @stdout.wait_writable(1) - @stdout.puts(format(str)) if @stdout.respond_to? :puts - @stdout.flush unless @stdout.sync - rescue Errno::EPIPE, Errno::EBADF + if @stdout.respond_to? :puts + internal_write { @stdout.puts format(str) } + end end def write(str) + internal_write { @stdout.write format(str) } + end + + def internal_write @stdout.is_a?(IO) and @stdout.wait_writable(1) - @stdout.write(format(str)) + yield @stdout.flush unless @stdout.sync rescue Errno::EPIPE, Errno::EBADF end + private :internal_write def debug(str) log("% #{str}") if @debug