Class: TinyIRC::AppLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/tinyirc/app.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AppLogger

Returns a new instance of AppLogger.



9
10
11
# File 'lib/tinyirc/app.rb', line 9

def initialize(app)
  @app = app
end

Class Attribute Details

.logObject

Returns the value of attribute log.



3
4
5
# File 'lib/tinyirc/app.rb', line 3

def log
  @log
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/tinyirc/app.rb', line 13

def call(env)
  @start = Time.now
  @status, @headers, @body = @app.call(env)
  @duration = ((Time.now - @start).to_f * 1000).round(2)

  TinyIRC::AppLogger.log.io "#{env['REMOTE_ADDR']} --- #{env['REQUEST_METHOD']} #{env['REQUEST_PATH']} --- #{@duration} ms"

  [@status, @headers, @body]
end