Class: Logrithm::Middleware::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/logrithm/middleware/rack.rb

Constant Summary collapse

MAXREADLEN =
2048

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ Rack

Returns a new instance of Rack.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/logrithm/middleware/rack.rb', line 13

def initialize(app, logger)
  # rubocop:disable Style/ParallelAssignment
  @app, @logger = app, logger
  # rubocop:enable Style/ParallelAssignment
  @rp, @wp = IO.pipe

  Thread.new do
    loop do
      begin
         @rp.read_nonblock(MAXREADLEN)
      rescue IO::WaitReadable
        IO.select([@rp])
        retry
      end
    end
  end
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
# File 'lib/logrithm/middleware/rack.rb', line 31

def call(env)
  IO.select(nil, [env['rack.errors'] = @wp])
  @app.call(env)
end

#(what) ⇒ Object

rubocop:disable Style/MethodName rubocop:disable Style/OpMethod



38
39
40
# File 'lib/logrithm/middleware/rack.rb', line 38

def (what)
  Logrithm.debug what unless what.blank?
end