Class: Puma::LogWriter
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/puma/log_writer.rb |
Overview
Constant Summary
-
DEFAULT =
# File 'lib/puma/log_writer.rb', line 44new(STDOUT, STDERR)
-
LOG_QUEUE =
# File 'lib/puma/log_writer.rb', line 26Queue.new
Class Method Summary
- .new(stdout, stderr) ⇒ LogWriter constructor
- .null
- .stdio
-
.strings
Returns an
LogWriter
object which writes its status to two StringIO objects.
Instance Attribute Summary
- #custom_logger rw
- #debug? ⇒ Boolean readonly
- #formatter rw
- #stderr readonly
- #stdout readonly
Instance Method Summary
-
#connection_error(error, req, text = "HTTP connection error")
An HTTP connection error has occurred.
- #debug(str) readonly
-
#debug_error(error, req = nil, text = "")
Log occurred error debug dump.
-
#error(str)
Write
str
to @stderr. - #format(str)
-
#log(str)
Write
str
to @stdout. -
#parse_error(error, req)
An HTTP parse error has occurred.
-
#ssl_error(error, ssl_socket)
An SSL error has occurred.
-
#unknown_error(error, req = nil, text = "Unknown error")
An unknown error has occurred.
- #write(str)
- #internal_write(str) private
Constructor Details
.new(stdout, stderr) ⇒ LogWriter
[ GitHub ]
# 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
Class Method Details
.null
[ GitHub ].stdio
[ GitHub ]# File 'lib/puma/log_writer.rb', line 52
def self.stdio LogWriter.new($stdout, $stderr) end
.strings
Returns an LogWriter
object which writes its status to two StringIO objects.
Instance Attribute Details
#custom_logger (rw)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 31
attr_accessor :formatter, :custom_logger
#debug? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/puma/log_writer.rb', line 89
def debug? @debug end
#formatter (rw)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 31
attr_accessor :formatter, :custom_logger
#stderr (readonly)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 28
attr_reader :stdout, :stderr
#stdout (readonly)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 28
attr_reader :stdout, :stderr
Instance Method Details
#connection_error(error, req, text = "HTTP connection error")
An HTTP connection error has occurred. #error a connection exception, req
the request, and text
additional info
#debug(str) (readonly)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 93
def debug(str) log("% #{str}") if @debug end
#debug_error(error, req = nil, text = "")
Log occurred error debug dump. #error an exception object, req
the request, and text
additional info
#error(str)
Write str
to @stderr
# File 'lib/puma/log_writer.rb', line 98
def error(str) @error_logger.info(text: @formatter.call("ERROR: #{str}")) exit 1 end
#format(str)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 103
def format(str) formatter.call(str) end
#internal_write(str) (private)
[ GitHub ]# 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
#log(str)
Write str
to @stdout
# 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
#parse_error(error, req)
An HTTP parse error has occurred. #error a parsing exception, and req
the request.
#ssl_error(error, ssl_socket)
An SSL error has occurred.
#unknown_error(error, req = nil, text = "Unknown error")
An unknown error has occurred. #error an exception object, req
the request, and text
additional info
#write(str)
[ GitHub ]# File 'lib/puma/log_writer.rb', line 70
def write(str) internal_write @formatter.call(str) end