Class: Sinatra::RequestLogger::ProxyLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/request-logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ ProxyLogger

Returns a new instance of ProxyLogger.



10
11
12
13
# File 'lib/sinatra/request-logger.rb', line 10

def initialize(logger)
  @buffer = StringIO.new("")
  @logger = logger
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



36
37
38
# File 'lib/sinatra/request-logger.rb', line 36

def method_missing(method, *args)
  @logger.send(method, *args)
end

Instance Method Details

#flushObject



21
22
23
# File 'lib/sinatra/request-logger.rb', line 21

def flush
  @buffer.flush
end

#puts(msg) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/sinatra/request-logger.rb', line 25

def puts(msg)
  @buffer.puts(msg)
  if msg.is_a?(Array)
    @logger.info(msg.map(&:chomp).join("\n"))
  elsif msg.is_a?(String)
    @logger.info(msg.chomp)
  else
    @logger.info(msg)
  end
end

#write(msg) ⇒ Object Also known as: <<



15
16
17
18
# File 'lib/sinatra/request-logger.rb', line 15

def write(msg)
  @buffer.write(msg)
  @logger.info(msg)
end