Sha256: 0e48fa8092feb8443074be081996451b3f02d219ae62678c1db0c89cdfd37cc6

Contents?: true

Size: 1.08 KB

Versions: 34

Compression:

Stored size: 1.08 KB

Contents

require 'smartkiosk/common'

module Smartkiosk
  class Client
    module Logging extend Smartkiosk::Common::Logging
      self.service = 'Web'

      class Middleware
        def initialize(app)
          @app = app
        end

        def call(env)
          began_at = Time.now

          env['rack.logger'] = Smartkiosk::Client::Logging.logger
          status, header, body = @app.call(env)
          header = Rack::Utils::HeaderHash.new(header)
          log(env, status, header, began_at)
          [status, header, body]
        end

        def log(env, status, header, began_at)
          now = Time.now
          length = extract_content_length(header)

          Smartkiosk::Client::Logging.logger.info "#{status.to_s[0..3]} #{env["REQUEST_METHOD"]} " <<
            "#{env["PATH_INFO"]}#{env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"]}, " <<
            "#{length} (#{now - began_at})"

        end

        def extract_content_length(headers)
          value = headers['Content-Length'] or return '-'
          value.to_s == '0' ? '-' : value
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
smartkiosk-client-0.2.1 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.2 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.19 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.18 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.17 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.16 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.15 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.14 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.13 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.12 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.11 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.10 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.9 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.8 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.7 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.6 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.5 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.4 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.3 lib/smartkiosk/client/logging.rb
smartkiosk-client-0.1.2 lib/smartkiosk/client/logging.rb