class Puma::LogWriter
Handles logging concerns for both standard messages (stdout) and errors (stderr).
Constants
- DEFAULT
- LOG_QUEUE
Attributes
Public Class Methods
Create a LogWriter that prints to stdout and stderr.
# File lib/puma/log_writer.rb, line 34 def initialize(stdout, stderr) @formatter = DefaultFormatter.new @stdout = stdout @stderr = stderr @debug = ENV.key?('PUMA_DEBUG') @error_logger = ErrorLogger.new(@stderr) end
# File lib/puma/log_writer.rb, line 55 def self.null n = NullIO.new LogWriter.new(n, n) end
# File lib/puma/log_writer.rb, line 51 def self.stdio LogWriter.new($stdout, $stderr) end
Returns an LogWriter object which writes its status to two StringIO objects.
# File lib/puma/log_writer.rb, line 47 def self.strings LogWriter.new(StringIO.new, StringIO.new) end
Public Instance Methods
An HTTP connection error has occurred. error a connection exception, req the request, and text additional info @version 5.0.0
# File lib/puma/log_writer.rb, line 101 def connection_error(error, req, text="HTTP connection error") @error_logger.info(error: error, req: req, text: text) end
# File lib/puma/log_writer.rb, line 83 def debug(str) log("% #{str}") if @debug end
Log occurred error debug dump. error an exception object, req the request, and text additional info @version 5.0.0
# File lib/puma/log_writer.rb, line 133 def debug_error(error, req=nil, text="") @error_logger.debug(error: error, req: req, text: text) end
Write str to +@stderr+
# File lib/puma/log_writer.rb, line 88 def error(str) @error_logger.info(text: @formatter.call("ERROR: #{str}")) exit 1 end
# File lib/puma/log_writer.rb, line 93 def format(str) formatter.call(str) end
Write str to +@stdout+
# File lib/puma/log_writer.rb, line 61 def log(str) internal_write "#{@formatter.call str}\n" end
An HTTP parse error has occurred. error a parsing exception, and req the request.
# File lib/puma/log_writer.rb, line 108 def parse_error(error, req) @error_logger.info(error: error, req: req, text: 'HTTP parse error, malformed request') end
An SSL error has occurred. @param error <Puma::MiniSSL::SSLError> @param ssl_socket <Puma::MiniSSL::Socket>
# File lib/puma/log_writer.rb, line 115 def ssl_error(error, ssl_socket) peeraddr = ssl_socket.peeraddr.last rescue "<unknown>" peercert = ssl_socket.peercert subject = peercert ? peercert.subject : nil @error_logger.info(error: error, text: "SSL error, peer: #{peeraddr}, peer cert: #{subject}") end
An unknown error has occurred. error an exception object, req the request, and text additional info
# File lib/puma/log_writer.rb, line 125 def unknown_error(error, req=nil, text="Unknown error") @error_logger.info(error: error, req: req, text: text) end
# File lib/puma/log_writer.rb, line 65 def write(str) internal_write @formatter.call(str) end
Private Instance Methods
# File lib/puma/log_writer.rb, line 69 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 end end rescue ThreadError end