Class: Puma::Events
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/puma/events.rb |
Overview
Constant Summary
-
DEFAULT =
# File 'lib/puma/events.rb', line 159new(STDOUT, STDERR)
Class Method Summary
- .new(stdout, stderr) ⇒ Events constructor
- .null
- .stdio
-
.strings
Returns an
Events
object which writes its status to 2 StringIO objects.
Instance Attribute Summary
- #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)
-
#debug_error(error, req = nil, text = "")
Log occurred error debug dump.
-
#error(str)
Write
str
to @stderr. -
#fire(hook, *args)
Fire callbacks for the named hook.
- #fire_on_booted!
- #fire_on_restart!
- #fire_on_stopped!
- #format(str)
-
#log(str)
Write
str
to @stdout. - #on_booted(&block)
- #on_restart(&block)
- #on_stopped(&block)
-
#parse_error(error, req)
An HTTP parse error has occurred.
-
#register(hook, obj = nil, &blk)
Register a callback for a given hook.
-
#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)
Constructor Details
.new(stdout, stderr) ⇒ Events
[ GitHub ]
# File 'lib/puma/events.rb', line 28
def initialize(stdout, stderr) @formatter = DefaultFormatter.new @stdout = stdout @stderr = stderr @debug = ENV.key? 'PUMA_DEBUG' @error_logger = ErrorLogger.new(@stderr) @hooks = Hash.new { |h,k| h[k] = [] } end
Class Method Details
.null
[ GitHub ].stdio
[ GitHub ]# File 'lib/puma/events.rb', line 168
def self.stdio Events.new $stdout, $stderr end
.strings
Returns an Events
object which writes its status to 2 StringIO objects.
Instance Attribute Details
#formatter (rw)
[ GitHub ]# File 'lib/puma/events.rb', line 40
attr_accessor :formatter
#stderr (readonly)
[ GitHub ]# File 'lib/puma/events.rb', line 39
attr_reader :stdout, :stderr
#stdout (readonly)
[ GitHub ]# File 'lib/puma/events.rb', line 39
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)
[ GitHub ]# File 'lib/puma/events.rb', line 75
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/events.rb', line 81
def error(str) @error_logger.info(text: format("ERROR: #{str}")) exit 1 end
#fire(hook, *args)
Fire callbacks for the named hook
# File 'lib/puma/events.rb', line 44
def fire(hook, *args) @hooks[hook].each { |t| t.call(*args) } end
#fire_on_booted!
[ GitHub ]#fire_on_restart!
[ GitHub ]# File 'lib/puma/events.rb', line 151
def fire_on_restart! fire(:on_restart) end
#fire_on_stopped!
[ GitHub ]# File 'lib/puma/events.rb', line 155
def fire_on_stopped! fire(:on_stopped) end
#format(str)
[ GitHub ]# File 'lib/puma/events.rb', line 86
def format(str) formatter.call(str) end
#log(str)
Write str
to @stdout
# File 'lib/puma/events.rb', line 64
def log(str) @stdout.puts format(str) if @stdout.respond_to? :puts @stdout.flush unless @stdout.sync rescue Errno::EPIPE end
#on_booted(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 135
def on_booted(&block) register(:on_booted, &block) end
#on_restart(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 139
def on_restart(&block) register(:on_restart, &block) end
#on_stopped(&block)
[ GitHub ]# File 'lib/puma/events.rb', line 143
def on_stopped(&block) register(:on_stopped, &block) end
#parse_error(error, req)
An HTTP parse error has occurred. #error a parsing exception, and req
the request.
#register(hook, obj = nil, &blk)
Register a callback for a given hook
# File 'lib/puma/events.rb', line 50
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
#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/events.rb', line 71
def write(str) @stdout.write format(str) end