Sha256: b3b8afe610f264e2ea1fa1bc9c731348f35a9c696c54a9a8aed312a454e0fc9f

Contents?: true

Size: 1.12 KB

Versions: 75

Compression:

Stored size: 1.12 KB

Contents

require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/object/blank'

module Rails
  module Rack
    # Log the request started and flush all loggers after it.
    class Logger < ActiveSupport::LogSubscriber
      def initialize(app, tags=nil)
        @app, @tags = app, tags.presence
      end

      def call(env)
        if @tags
          Rails.logger.tagged(compute_tags(env)) { call_app(env) }
        else
          call_app(env)
        end
      end

    protected

      def call_app(env)
        request = ActionDispatch::Request.new(env)
        path = request.filtered_path
        Rails.logger.info "\n\nStarted #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}"
        @app.call(env)
      ensure
        ActiveSupport::LogSubscriber.flush_all!
      end

      def compute_tags(env)
        request = ActionDispatch::Request.new(env)

        @tags.collect do |tag|
          case tag
          when Proc
            tag.call(request)
          when Symbol
            request.send(tag)
          else
            tag
          end
        end
      end
    end
  end
end

Version data entries

75 entries across 53 versions & 6 rubygems

Version Path
railties-3.2.4 lib/rails/rack/logger.rb
railties-3.2.4.rc1 lib/rails/rack/logger.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/rack/logger.rb
challah-0.6.0 vendor/bundle/gems/railties-3.2.1/lib/rails/rack/logger.rb
challah-0.6.0 vendor/bundle/gems/railties-3.2.2/lib/rails/rack/logger.rb
challah-0.6.0 vendor/bundle/gems/railties-3.2.3/lib/rails/rack/logger.rb
challah-0.5.4 vendor/bundle/gems/railties-3.2.2/lib/rails/rack/logger.rb
challah-0.5.4 vendor/bundle/gems/railties-3.2.1/lib/rails/rack/logger.rb
railties-3.2.3 lib/rails/rack/logger.rb
railties-3.2.3.rc2 lib/rails/rack/logger.rb
railties-3.2.3.rc1 lib/rails/rack/logger.rb
challah-0.5.3 vendor/bundle/gems/railties-3.2.1/lib/rails/rack/logger.rb
challah-0.5.3 vendor/bundle/gems/railties-3.2.2/lib/rails/rack/logger.rb
challah-0.5.2 vendor/bundle/gems/railties-3.2.1/lib/rails/rack/logger.rb
challah-0.5.2 vendor/bundle/gems/railties-3.2.2/lib/rails/rack/logger.rb
challah-0.5.1 vendor/bundle/gems/railties-3.2.2/lib/rails/rack/logger.rb
railties-3.2.2 lib/rails/rack/logger.rb
railties-3.2.2.rc1 lib/rails/rack/logger.rb