1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma/tcp_logger.rb

32 lines
661 B
Ruby

module Puma
class TCPLogger
def initialize(logger, app, quiet=false)
@logger = logger
@app = app
@quiet = quiet
end
FORMAT = "%s - %s"
def log(who, str)
now = Time.now.strftime("%d/%b/%Y %H:%M:%S")
@logger.puts "#{now} - #{who} - #{str}"
end
def call(env, socket)
who = env[Const::REMOTE_ADDR]
log who, "connected" unless @quiet
env['log'] = lambda { |str| log(who, str) }
begin
@app.call env, socket
rescue Object => e
log who, "exception: #{e.message} (#{e.class})"
else
log who, "disconnected" unless @quiet
end
end
end
end