class Puma::Events

The default implement of an event sink object used by Server for when certain kinds of events occur in the life of the server.

The methods available are the events that the Server fires.

Constants

DEFAULT

Attributes

stderr[R]
stdout[R]

Public Class Methods

new(stdout, stderr) click to toggle source

Create an Events object that prints to stdout and stderr.

# File lib/puma/events.rb, line 16
def initialize(stdout, stderr)
  @stdout = stdout
  @stderr = stderr

  @stdout.sync = true
  @stderr.sync = true
end
strings() click to toggle source

Returns an Events object which writes it’s status to 2 StringIO objects.

# File lib/puma/events.rb, line 66
def self.strings
  Events.new StringIO.new, StringIO.new
end

Public Instance Methods

error(str) click to toggle source

Write str to +@stderr+

# File lib/puma/events.rb, line 34
def error(str)
  @stderr.puts "ERROR: #{str}"
  exit 1
end
log(str) click to toggle source

Write str to +@stdout+

# File lib/puma/events.rb, line 28
def log(str)
  @stdout.puts str
end
parse_error(server, env, error) click to toggle source

An HTTP parse error has occured. server is the Server object, env the request, and error a parsing exception.

# File lib/puma/events.rb, line 43
def parse_error(server, env, error)
  @stderr.puts "#{Time.now}: HTTP parse error, malformed request (#{env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR]}): #{error.inspect}"
  @stderr.puts "#{Time.now}: ENV: #{env.inspect}\n---\n"
end
unknown_error(server, error, kind="Unknown") click to toggle source

An unknown error has occured. server is the Server object, env the request, error an exception object, and kind some additional info.

# File lib/puma/events.rb, line 52
def unknown_error(server, error, kind="Unknown")
  if error.respond_to? :render
    error.render "#{Time.now}: #{kind} error", @stderr
  else
    @stderr.puts "#{Time.now}: #{kind} error: #{error.inspect}"
    @stderr.puts error.backtrace.join("\n")
  end
end