Sha256: b43d22e49039fe717713c6c446621c1e45df4720e88d48802e6cf5aa76636a5e

Contents?: true

Size: 701 Bytes

Versions: 6

Compression:

Stored size: 701 Bytes

Contents

module Locomotive::Builder
  class Server

    # Track the request into the current logger
    #
    class Logging < Middleware

      def call(env)
        now = Time.now

        log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}"

        app.call(env).tap do |response|
          done_in_ms = (Time.now - now) * 1000
          log "Completed #{code_to_human(response.first)} in #{done_in_ms}ms\n\n"
        end
      end

      protected

      def code_to_human(code)
        case code.to_i
        when 200 then '200 OK'
        when 301 then '301 Found'
        when 302 then '302 Found'
        when 404 then '404 Not Found'
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_builder-1.0.0.alpha8 lib/locomotive/builder/server/logging.rb
locomotivecms_builder-1.0.0.alpha7 lib/locomotive/builder/server/logging.rb
locomotivecms_builder-1.0.0.alpha6 lib/locomotive/builder/server/logging.rb
locomotivecms_builder-1.0.0.alpha5 lib/locomotive/builder/server/logging.rb
locomotivecms_builder-1.0.0.alpha4 lib/locomotive/builder/server/logging.rb
locomotivecms_builder-1.0.0.alpha3 lib/locomotive/builder/server/logging.rb