Sha256: 19a86b7947df24d67550779cfd0c8b7ea5130d5a204f6721187410074454566c

Contents?: true

Size: 891 Bytes

Versions: 7

Compression:

Stored size: 891 Bytes

Contents

module Locomotive::Steam
  module Middlewares

    # Track the request into the current logger
    #
    class Logging < Struct.new(:app)

      include Helpers

      def call(env)
        now = Time.now

        log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}".light_white, 0
        log "Params: #{env.fetch('steam.request').params.inspect}"

        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".green
        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'
        when 422 then '422 Unprocessable Entity'
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.0.0.pre.alpha lib/locomotive/steam/middlewares/logging.rb