class Puma::LogWriter
Handles logging concerns for both standard messages (stdout
) and errors (stderr
).
Constants
- DEFAULT
- LOG_QUEUE
Attributes
Public Class Methods
Source
# File lib/puma/log_writer.rb, line 34 def initialize(stdout, stderr) @formatter = DefaultFormatter.new @custom_logger = nil @stdout = stdout @stderr = stderr @debug = ENV.key?('PUMA_DEBUG') @error_logger = ErrorLogger.new(@stderr) end
Create a LogWriter
that prints to stdout
and stderr
.
Source
# File lib/puma/log_writer.rb, line 56 def self.null n = NullIO.new LogWriter.new(n, n) end
Source
# File lib/puma/log_writer.rb, line 52 def self.stdio LogWriter.new($stdout, $stderr) end
Source
# File lib/puma/log_writer.rb, line 48 def self.strings LogWriter.new(StringIO.new, StringIO.new) end
Returns an LogWriter
object which writes its status to two StringIO objects.
Public Instance Methods
Source
# File lib/puma/log_writer.rb, line 111 def connection_error(error, req, text="HTTP connection error") @error_logger.info(error: error, req: req, text: text) end
An HTTP connection error has occurred. error
a connection exception, req
the request, and text
additional info @version 5.0.0
Source
# File lib/puma/log_writer.rb, line 93 def debug(str) log("% #{str}") if @debug end
Source
# File lib/puma/log_writer.rb, line 143 def debug_error(error, req=nil, text="") @error_logger.debug(error: error, req: req, text: text) end
Log occurred error debug dump. error
an exception object, req
the request, and text
additional info @version 5.0.0
Source
# File lib/puma/log_writer.rb, line 98 def error(str) @error_logger.info(text: @formatter.call("ERROR: #{str}")) exit 1 end
Write str
to +@stderr+
Source
# File lib/puma/log_writer.rb, line 62 def log(str) if @custom_logger&.respond_to?(:write) @custom_logger.write(format(str)) else internal_write "#{@formatter.call str}\n" end end
Write str
to +@stdout+
Source
# File lib/puma/log_writer.rb, line 118 def parse_error(error, req) @error_logger.info(error: error, req: req, text: 'HTTP parse error, malformed request') end
An HTTP parse error has occurred. error
a parsing exception, and req
the request.
Source
# File lib/puma/log_writer.rb, line 125 def ssl_error(error, ssl_socket) peeraddr = ssl_socket.peeraddr.last rescue "<unknown>" peercert = ssl_socket.peercert subject = peercert&.subject @error_logger.info(error: error, text: "SSL error, peer: #{peeraddr}, peer cert: #{subject}") end
An SSL error has occurred. @param error <Puma::MiniSSL::SSLError> @param ssl_socket <Puma::MiniSSL::Socket>
Source
# File lib/puma/log_writer.rb, line 135 def unknown_error(error, req=nil, text="Unknown error") @error_logger.info(error: error, req: req, text: text) end
An unknown error has occurred. error
an exception object, req
the request, and text
additional info
Source
# File lib/puma/log_writer.rb, line 70 def write(str) internal_write @formatter.call(str) end
Private Instance Methods
Source
# File lib/puma/log_writer.rb, line 74 def internal_write(str) LOG_QUEUE << str while (w_str = LOG_QUEUE.pop(true)) do begin @stdout.is_a?(IO) and @stdout.wait_writable(1) @stdout.write w_str @stdout.flush unless @stdout.sync rescue Errno::EPIPE, Errno::EBADF, IOError, Errno::EINVAL # 'Invalid argument' (Errno::EINVAL) may be raised by flush end end rescue ThreadError end