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.
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 @debug = ENV.key? 'PUMA_DEBUG' @on_booted = [] @hooks = Hash.new { |h,k| h[k] = [] } end
# File lib/puma/events.rb, line 112 def self.stdio Events.new $stdout, $stderr end
Returns an Events object which writes it’s status to 2 StringIO objects.
# File lib/puma/events.rb, line 108 def self.strings Events.new StringIO.new, StringIO.new end
# File lib/puma/events.rb, line 62 def debug(str) log("% #{str}") if @debug end
Write str to +@stderr+
# File lib/puma/events.rb, line 68 def error(str) @stderr.puts "ERROR: #{str}" exit 1 end
Fire callbacks for the named hook
# File lib/puma/events.rb, line 34 def fire(hook, *args) @hooks[hook].each { |t| t.call(*args) } end
# File lib/puma/events.rb, line 99 def fire_on_booted! @on_booted.each { |b| b.call } end
Write str to +@stdout+
# File lib/puma/events.rb, line 54 def log(str) @stdout.puts str end
# File lib/puma/events.rb, line 95 def on_booted(&b) @on_booted << b end
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 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 a callbock for a given hook
# File 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
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 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
Generated with the Darkfish Rdoc Generator 2.