Sha256: 1e846a7a61c07a6b1a0ab72cae8065878c39e28ce29751ebeb47f304d48c84f3

Contents?: true

Size: 808 Bytes

Versions: 55

Compression:

Stored size: 808 Bytes

Contents

# frozen_string_literal: true

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")

      log_str = "#{now} - #{who} - #{str}"

      case @logger
      when IO
        @logger.puts log_str
      when Events
        @logger.log log_str
      end
    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

Version data entries

55 entries across 55 versions & 5 rubygems

Version Path
puma-4.3.12-java lib/puma/tcp_logger.rb
puma-4.3.12 lib/puma/tcp_logger.rb
puma-4.3.11-java lib/puma/tcp_logger.rb
puma-4.3.11 lib/puma/tcp_logger.rb
puma-4.3.10-java lib/puma/tcp_logger.rb
puma-4.3.10 lib/puma/tcp_logger.rb
puma-4.3.9 lib/puma/tcp_logger.rb
puma-4.3.9-java lib/puma/tcp_logger.rb
puma-4.3.8-java lib/puma/tcp_logger.rb
puma-4.3.8 lib/puma/tcp_logger.rb
puma-4.3.7-java lib/puma/tcp_logger.rb
puma-4.3.7 lib/puma/tcp_logger.rb
piesync-puma-3.12.6.1 lib/puma/tcp_logger.rb
piesync-puma-3.12.6 lib/puma/tcp_logger.rb
puma-4.3.6-java lib/puma/tcp_logger.rb
puma-4.3.6 lib/puma/tcp_logger.rb
gitlab-puma-4.3.5.gitlab.3 lib/puma/tcp_logger.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/puma-4.3.0/lib/puma/tcp_logger.rb
puma-4.3.5-java lib/puma/tcp_logger.rb
puma-4.3.5 lib/puma/tcp_logger.rb