Sha256: 184d63ef87e584a079f59c722ba85feb58ce6c8b58e276d3aad69157ca6bd1b8

Contents?: true

Size: 968 Bytes

Versions: 15

Compression:

Stored size: 968 Bytes

Contents

require 'logger'
require 'rack/commonlogger'
require_relative 'log_wrapper'
require 'sitehub/constants'
require 'sitehub/middleware/logging/request_log'
require 'sitehub/response'

class SiteHub
  module Middleware
    module Logging
      class AccessLogger
        attr_reader :logger, :start_time

        include Constants

        FORMAT = %(%s - %s [%s] transaction_id:%s: "%s %s%s => %s %s" %d %s %0.4f\n).freeze
        ZERO_STRING = '0'.freeze
        STATUS_RANGE = 0..3

        def initialize(app, logger = ::Logger.new(STDOUT))
          @app = app
          @logger = LogWrapper.new(logger)
        end

        def call(env)
          request = env[REQUEST] = Request.new(env: env)
          @app.call(env).tap do |response|
            status, headers, body = response.to_a
            response = Response.new(body, status, headers)
            logger.write(RequestLog.new(request, response).to_s)
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.4.10 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha11 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha10 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha8 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha7 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha6 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha5 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha4 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha3 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.5.0.alpha2 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.4.9 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.4.8 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.4.7 lib/sitehub/middleware/logging/access_logger.rb
sitehub-0.4.6 lib/sitehub/middleware/logging/access_logger.rb