Sha256: 333a1f83722610899a2ad60a81339e4469d2ea3920c5d5b62bd3a7b235c9192a

Contents?: true

Size: 718 Bytes

Versions: 3

Compression:

Stored size: 718 Bytes

Contents

module Locomotive::Wagon
  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) * 10000).truncate / 10.0
          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

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.2.2 lib/locomotive/wagon/server/logging.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/server/logging.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/server/logging.rb