Class: Puma::LogWriter
- Inherits:
-
Object
- Object
- Puma::LogWriter
- Defined in:
- lib/puma/log_writer.rb
Overview
Handles logging concerns for both standard messages (stdout
) and errors (stderr
).
Defined Under Namespace
Classes: DefaultFormatter, PidFormatter
Constant Summary collapse
- LOG_QUEUE =
Queue.new
- DEFAULT =
new(STDOUT, STDERR)
Instance Attribute Summary collapse
-
#custom_logger ⇒ Object
Returns the value of attribute custom_logger.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
- .null(env: ENV) ⇒ Object
- .stdio(env: ENV) ⇒ Object
-
.strings(env: ENV) ⇒ Object
Returns an LogWriter object which writes its status to two StringIO objects.
Instance Method Summary collapse
-
#connection_error(error, req, text = "HTTP connection error") ⇒ Object
An HTTP connection error has occurred.
- #debug(str) ⇒ Object
- #debug? ⇒ Boolean
-
#debug_error(error, req = nil, text = "") ⇒ Object
Log occurred error debug dump.
-
#error(str) ⇒ Object
Write
str
to @stderr. - #format(str) ⇒ Object
-
#initialize(stdout, stderr, env: ENV) ⇒ LogWriter
constructor
Create a LogWriter that prints to
stdout
andstderr
. -
#log(str) ⇒ Object
Write
str
to @stdout. -
#parse_error(error, req) ⇒ Object
An HTTP parse error has occurred.
-
#ssl_error(error, ssl_socket) ⇒ Object
An SSL error has occurred.
-
#unknown_error(error, req = nil, text = "Unknown error") ⇒ Object
An unknown error has occurred.
- #write(str) ⇒ Object
Constructor Details
#initialize(stdout, stderr, env: ENV) ⇒ LogWriter
Create a LogWriter that prints to stdout
and stderr
.
34 35 36 37 38 39 40 41 42 |
# File 'lib/puma/log_writer.rb', line 34 def initialize(stdout, stderr, env: ENV) @formatter = DefaultFormatter.new @custom_logger = nil @stdout = stdout @stderr = stderr @debug = env.key?('PUMA_DEBUG') @error_logger = ErrorLogger.new(@stderr, env: env) end |
Instance Attribute Details
#custom_logger ⇒ Object
Returns the value of attribute custom_logger.
31 32 33 |
# File 'lib/puma/log_writer.rb', line 31 def custom_logger @custom_logger end |
#formatter ⇒ Object
Returns the value of attribute formatter.
31 32 33 |
# File 'lib/puma/log_writer.rb', line 31 def formatter @formatter end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
28 29 30 |
# File 'lib/puma/log_writer.rb', line 28 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
28 29 30 |
# File 'lib/puma/log_writer.rb', line 28 def stdout @stdout end |
Class Method Details
.null(env: ENV) ⇒ Object
56 57 58 59 |
# File 'lib/puma/log_writer.rb', line 56 def self.null(env: ENV) n = NullIO.new LogWriter.new(n, n, env: env) end |
Instance Method Details
#connection_error(error, req, text = "HTTP connection error") ⇒ Object
An HTTP connection error has occurred. error
a connection exception, req
the request, and text
additional info
111 112 113 |
# 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 |
#debug(str) ⇒ Object
93 94 95 |
# File 'lib/puma/log_writer.rb', line 93 def debug(str) log("% #{str}") if @debug end |
#debug? ⇒ Boolean
89 90 91 |
# File 'lib/puma/log_writer.rb', line 89 def debug? @debug end |
#debug_error(error, req = nil, text = "") ⇒ Object
Log occurred error debug dump. error
an exception object, req
the request, and text
additional info
143 144 145 |
# 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 |
#error(str) ⇒ Object
Write str
to @stderr
98 99 100 101 |
# File 'lib/puma/log_writer.rb', line 98 def error(str) @error_logger.info(text: @formatter.call("ERROR: #{str}")) exit 1 end |
#format(str) ⇒ Object
103 104 105 |
# File 'lib/puma/log_writer.rb', line 103 def format(str) formatter.call(str) end |
#log(str) ⇒ Object
Write str
to @stdout
62 63 64 65 66 67 68 |
# 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) ⇒ Object
An HTTP parse error has occurred. error
a parsing exception, and req
the request.
118 119 120 |
# 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 |
#ssl_error(error, ssl_socket) ⇒ Object
An SSL error has occurred.
125 126 127 128 129 130 |
# 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 |
#unknown_error(error, req = nil, text = "Unknown error") ⇒ Object
An unknown error has occurred. error
an exception object, req
the request, and text
additional info
135 136 137 |
# 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 |
#write(str) ⇒ Object
70 71 72 |
# File 'lib/puma/log_writer.rb', line 70 def write(str) internal_write @formatter.call(str) end |