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 vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 16 def initialize(stdout, stderr) @stdout = stdout @stderr = stderr @stdout.sync = true @stderr.sync = true @debug = ENV.key? 'PUMA_DEBUG' @on_booted = [] @hooks = Hash.new { |h,k| h[k] = [] } end
stdio()
click to toggle source
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 112 def self.stdio Events.new $stdout, $stderr end
strings()
click to toggle source
Returns an Events
object which writes it's status to 2 StringIO objects.
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 108 def self.strings Events.new StringIO.new, StringIO.new end
Public Instance Methods
debug(str)
click to toggle source
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 62 def debug(str) log("% #{str}") if @debug end
error(str)
click to toggle source
Write str
to +@stderr+
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 68 def error(str) @stderr.puts "ERROR: #{str}" exit 1 end
fire(hook, *args)
click to toggle source
Fire callbacks for the named hook
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 34 def fire(hook, *args) @hooks[hook].each { |t| t.call(*args) } end
fire_on_booted!()
click to toggle source
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 99 def fire_on_booted! @on_booted.each { |b| b.call } end
log(str)
click to toggle source
Write str
to +@stdout+
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 54 def log(str) @stdout.puts str end
on_booted(&b)
click to toggle source
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 95 def on_booted(&b) @on_booted << b 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 vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 77 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
register(hook, obj=nil, &blk)
click to toggle source
Register a callbock for a given hook
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 40 def register(hook, obj=nil, &blk) if obj and blk raise "Specify either an object or a block, not both" end h = obj || blk @hooks[hook] << h h 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 vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 86 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
write(str)
click to toggle source
# File vendor/gems/puma-2.8.2-java/lib/puma/events.rb, line 58 def write(str) @stdout.write str end