Sha256: 55cacc0c198940d6a3dc0c13dc7ad7484ccb682188739d67bb00152676e8b5d0

Contents?: true

Size: 909 Bytes

Versions: 30

Compression:

Stored size: 909 Bytes

Contents

module Locomotive::Steam
  module Middlewares

    # Track the request into the current logger
    #
    class Logging

      include Helpers

      attr_accessor_initialize :app

      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

30 entries across 30 versions & 1 rubygems

Version Path
locomotivecms_steam-1.4.1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.1.2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.1.0 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.1.0.rc3 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.1.0.rc2 lib/locomotive/steam/middlewares/logging.rb
locomotivecms_steam-1.1.0.rc1 lib/locomotive/steam/middlewares/logging.rb