Sha256: 9df0a4e3b334f764775cadabf2b5c981c919aad402e34607f720d355bde1daf2

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

module Pakyow
  module Middleware
    class Logger
      def initialize(app)
        @app = app
      end
      
      def call(env)
        result = nil
        difference = time { |began_at|
          Log.enter "Processing #{env['PATH_INFO']} (#{env['REMOTE_ADDR']} at #{began_at}) [#{env['REQUEST_METHOD']}]"
          
          if error = catch(:error) { 
                      result = @app.call(env)
                      nil 
                    }
            Log.enter "[500] #{error}\n"
            Log.enter error.backtrace.join("\n") + "\n\n"
            
            result = Pakyow.app.response.finish
          end
        }
        
        Log.enter "Completed in #{difference}ms | #{Pakyow.app.response.status} | [#{Pakyow.app.request.url}]"
        Log.enter

        result
      end

      def time
        s = Time.now
        yield(s)
        (Time.now.to_f - s.to_f) * 1000.0
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pakyow-core-0.8rc1 pakyow-core/lib/core/middleware/logger.rb