Class: Puma::Events

### Home Classes Methods

### In Files

- lib/puma/events.rb

### Parent

Object

### Namespace

- CLASS Puma::Events::DefaultFormatter
- CLASS Puma::Events::PidFormatter

### Methods

- ::new
- ::stdio
- ::strings
- #debug
- #error
- #fire
- #fire_on_booted!
- #format
- #log
- #on_booted
- #parse_error
- #register
- #ssl_error
- #unknown_error
- #write

### Included Modules

- Puma::Const

### Files

- Manifest.txt

### Class/Module Index

Quicksearch

- Puma
- Puma::App
- Puma::App::Status
- Puma::Binder
- Puma::CLI
- Puma::Client
- Puma::Cluster
- Puma::Cluster::Worker
- Puma::CommonLogger
- Puma::ConfigDefault
- Puma::Configuration
- Puma::Configuration::ConfigMiddleware
- Puma::ConnectionError
- Puma::Const
- Puma::ControlCLI
- Puma::DSL
- Puma::Delegation
- Puma::Events
- Puma::Events::DefaultFormatter
- Puma::Events::PidFormatter
- Puma::IOBuffer
- Puma::JRubyRestart
- Puma::JavaIOBuffer
- Puma::MiniSSL
- Puma::MiniSSL::Context
- Puma::MiniSSL::SSLError
- Puma::MiniSSL::Server
- Puma::MiniSSL::Socket
- Puma::NullIO
- Puma::Rack
- Puma::Rack::Builder
- Puma::Rack::Options
- Puma::Rack::URLMap
- Puma::Reactor
- Puma::Runner
- Puma::Server
- Puma::Single
- Puma::TCPLogger
- Puma::ThreadPool
- Puma::ThreadPool::AutoTrim
- Puma::ThreadPool::Reaper
- Puma::UnsupportedOption
- Puma::Util
- Puma::Util::HeaderHash
- OpenSSL
- OpenSSL::SSL
- OpenSSL::SSL::SSLServer
- Rack
- Rack::Handler
- Rack::Handler::Puma
- IO
- IO::WaitReadable
- Object
- Process
- String

No matching classes.

# 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

formatter[RW]
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 27
    def initialize(stdout, stderr)
      @formatter = DefaultFormatter.new
      @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 lib/puma/events.rb, line 138
    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 lib/puma/events.rb, line 134
    def self.strings
      Events.new StringIO.new, StringIO.new
    end

### Public Instance Methods

debug(str) click to toggle source

    # File lib/puma/events.rb, line 75
    def debug(str)
      log("% #{str}") if @debug
    end

error(str) click to toggle source

Write `str` to +@stderr+

    # File lib/puma/events.rb, line 81
    def error(str)
      @stderr.puts format("ERROR: #{str}")
      exit 1
    end

fire(hook, *args) click to toggle source

Fire callbacks for the named hook

    # File lib/puma/events.rb, line 47
    def fire(hook, *args)
      @hooks[hook].each { |t| t.call(*args) }
    end

fire_on_booted!() click to toggle source

    # File lib/puma/events.rb, line 125
    def fire_on_booted!
      @on_booted.each { |b| b.call }
    end

format(str) click to toggle source

    # File lib/puma/events.rb, line 86
    def format(str)
      formatter.call(str)
    end

log(str) click to toggle source

Write `str` to +@stdout+

    # File lib/puma/events.rb, line 67
    def log(str)
      @stdout.puts format(str)
    end

on_booted(&b) click to toggle source

    # File lib/puma/events.rb, line 121
    def on_booted(&b)
      @on_booted << b
    end

parse_error(server, env, error) click to toggle source

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

    # File lib/puma/events.rb, line 94
    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 lib/puma/events.rb, line 53
    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(server, peeraddr, peercert, error) click to toggle source

An SSL error has occurred. `server` is the Server object, `peeraddr` peer address, `peercert` any peer certificate (if present), and `error` an exception object.

    # File lib/puma/events.rb, line 103
    def ssl_error(server, peeraddr, peercert, error)
      subject = peercert ? peercert.subject : nil
      @stderr.puts "#{Time.now}: SSL error, peer: #{peeraddr}, peer cert: #{subject}, #{error.inspect}"
    end

unknown_error(server, error, kind="Unknown") click to toggle source

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

    # File lib/puma/events.rb, line 112
    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 lib/puma/events.rb, line 71
    def write(str)
      @stdout.write format(str)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.